From 078d2eabc0cf78b080164c8c84f22df79b2ff3b8 Mon Sep 17 00:00:00 2001 From: Izel Nakri Date: Fri, 14 Jan 2022 14:00:22 +0100 Subject: [PATCH] assert.partialEqual implementation --- src/assert.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/assert.js b/src/assert.js index c96b701aa..c0571daeb 100644 --- a/src/assert.js +++ b/src/assert.js @@ -216,6 +216,45 @@ class Assert { } ); } + partialEqual( actual, expected, message ) { + [ actual, expected ] = Object.keys( expected ).reduce( + ( result, key ) => { + result[ 0 ][ key ] = actual[ key ]; + result[ 1 ][ key ] = expected[ key ]; + + return result; + }, + [ {}, {} ] + ); + + this.pushResult( { + result: equiv( actual, expected ), + actual, + expected, + message + } ); + } + + notPartialEqual( actual, expected, message ) { + [ actual, expected ] = Object.keys( expected ).reduce( + ( result, key ) => { + result[ 0 ][ key ] = actual[ key ]; + result[ 1 ][ key ] = expected[ key ]; + + return result; + }, + [ {}, {} ] + ); + + this.pushResult( { + result: !equiv( actual, expected ), + actual, + expected, + message, + negative: true + } ); + } + deepEqual( actual, expected, message ) { this.pushResult( { result: equiv( actual, expected ),