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 }); // ?

Explanation

Use toBe for primitives and identity checks, toEqual for objects and arrays.

Further reading

Problem with a question

Testing · Junior · question 16

Test yourself

Take the Testing · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz