August 2017
Beginner
374 pages
10h 41m
English
The toBe matcher uses === to test for exact equality. This works well for primitive values such as numbers or strings.
If you want to check the value/contents of objects, you need to use toEqual instead, because two objects are never the exact same (even if they have the same contents). For example:
test('object example', () => { const data = { hello: 'world' } data['hi'] = 'world' expect(data).toEqual({ hello: 'world', hi: 'world' })})
It is also possible to negate matchers by adding a not. prefix; for example, expect(1 + 1).not.toBe(0).
Read now
Unlock full access