Created
October 10, 2017 19:48
-
-
Save MicheleBertoli/1eb979448a07cae86ca293fbda42a9d4 to your computer and use it in GitHub Desktop.
toBeShallowInstanceOf
This file contains 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
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