Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created October 10, 2017 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MicheleBertoli/1eb979448a07cae86ca293fbda42a9d4 to your computer and use it in GitHub Desktop.
Save MicheleBertoli/1eb979448a07cae86ca293fbda42a9d4 to your computer and use it in GitHub Desktop.
toBeShallowInstanceOf
expect.extend({
toBeShallowInstanceOf(received, argument) {
const pass = Object.getPrototypeOf(received) === argument.prototype
return {
message: () => (pass ? 'OK' : 'KO'),
pass,
}
},
})
function Car(make, model, year) {
this.make = make
this.model = model
this.year = year
}
const mycar = new Car('Honda', 'Accord', 1998)
test('toBeShallowInstanceOf', () => {
expect(mycar).toBeShallowInstanceOf(Car)
expect(mycar).toBeInstanceOf(Car)
expect(mycar).not.toBeShallowInstanceOf(Object)
expect(mycar).toBeInstanceOf(Object)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment