Skip to content

Instantly share code, notes, and snippets.

@andreipfeiffer
Last active August 8, 2021 06:04
Show Gist options
  • Save andreipfeiffer/bc38ee6387e8cfe6f1a87e8a01d02a13 to your computer and use it in GitHub Desktop.
Save andreipfeiffer/bc38ee6387e8cfe6f1a87e8a01d02a13 to your computer and use it in GitHub Desktop.
expect.extend({
toContainObject(received, argument) {
const pass = this.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
}
}
}
})
const state = [
{ type: 'START', data: 'foo' },
{ type: 'START', data: 'baz' },
{ type: 'END', data: 'foo' },
]
expect(state).toContainObject({ type: 'START' })
expect(state).toContainObject({ type: 'END' })
expect(state).toContainObject({ data: 'foo' })
expect(state).not.toContainObject({ type: 'NONE' })
expect(state).not.toContainObject({ data: 'bar' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment