Created
March 5, 2020 09:53
-
-
Save shts/ecaeaa09e7ae948eb47e9f22a85b423a to your computer and use it in GitHub Desktop.
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
describe('Matchers', () => { | |
describe('Compare "toBe" to "toEqual"', () => { | |
it('number', () => { | |
expect(1 + 1).toBe(2) // ok | |
expect(1 + 1).toEqual(2) // ok | |
}) | |
it('string', () => { | |
expect('d' + 'b').toBe('db') // ok | |
expect('d' + 'b').toEqual('db') // ok | |
}) | |
it('object', () => { | |
const user = { name: 'Hoge', age: 30 } | |
// expect(user).toBe({ name: 'Hoge', age: 30 }) // Fail | |
expect(user).toEqual({ name: 'Hoge', age: 30 }) | |
}) | |
it('date', () => { | |
const date = new Date('2020/01/01 00:00:00') | |
// expect(date).toBe(new Date('2020/01/01 00:00:00')) // Fail | |
expect(date).toEqual(new Date('2020/01/01 00:00:00')) | |
}) | |
it('class', () => { | |
class User { | |
age: number | |
constructor(age:number) { | |
this.age = age | |
} | |
} | |
const user = new User(30) | |
// expect(user).toBe(new User(30)) // Fail | |
expect(user).toEqual(new User(30)) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment