Skip to content

Instantly share code, notes, and snippets.

@isocroft
Created June 16, 2025 10:58
Show Gist options
  • Save isocroft/820ae4e6cd0f78ed19581b6e2323f43b to your computer and use it in GitHub Desktop.
Save isocroft/820ae4e6cd0f78ed19581b6e2323f43b to your computer and use it in GitHub Desktop.
This is a file that holds a good amount of custom matchers for Jest
expect.extend({
toBeArrayContainingObject(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
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment