Testing · Junior · Question 16 of 78
What is the difference between toBe and toEqual?
expect({ a: 1 }).toBe({ a: 1 }); // ?
expect({ a: 1 }).toEqual({ a: 1 }); // ?- ✓Correct answer:
toBecompares withObject.is(same reference),toEqualcompares contents recursively - the first fails, the second passes - 2Both pass: they are synonyms
- 3Both fail: objects can't be compared
Explanation
Use toBe for primitives and identity checks, toEqual for objects and arrays.