Created
November 17, 2020 06:57
-
-
Save xalakox/8253b1b11fbc5468aa89fb027bb7b6b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { equals } = require('expect/build/jasmineUtils'); | |
expect.extend({ | |
toContainObject(received, argument) { | |
const pass = (() => { | |
if (Array.isArray(argument)) { | |
return equals(received, | |
expect.arrayContaining(argument.map(arg => expect.objectContaining(arg))) | |
); | |
} | |
return equals(received, | |
expect.arrayContaining([ | |
expect.objectContaining(argument) | |
]) | |
); | |
})(); | |
if (pass) { | |
return { | |
message: () => (`expected ${this.utils.printReceived(received)} not to contain object ${this.utils.printExpected(argument)}`), | |
pass: true | |
} | |
} else { | |
return { | |
message: () => (`expected ${this.utils.printReceived(received)} to contain object ${this.utils.printExpected(argument)}`), | |
pass: false | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example usage on a first level and nested object: (should pass)