Quiz Yourself on Matchers
This quiz will test what you have learned in this chapter.
1
A test uses the toBe
matcher to test the result of a function call. However, the test is unexpectedly failing. What do you think the problem is, and how can it be resolved?
expect(response).toBe({
success: true,
productId: 1,
});
A)
The toBe
matcher will check that the objects’ references are equivalent, which won’t be the case. The toStrictEqual
or toEqual
functions could be used instead.
B)
The expected object’s properties are ordered incorrectly. The productId
needs to be placed before success
.
C)
The toBe
function can’t be used to check objects, so toBeObj
should be used instead.
Question 1 of 80 attempted
Get hands-on with 1400+ tech skills courses.