Closed carlnoval closed 1 year ago
@carlnoval can you please provide me with the actual value of the movie.json()
so that I can try running this locally?
const movieJson = await movie.json();
console.log(movieJson);
@aslushnikov Above code generates below json.
{
success: false,
status_code: 34,
status_message: 'The resource you requested could not be found.'
}
@carlnoval your movieJson
is not an array; the method toContainEqual
expects it to be an array:
Use .toContainEqual when you want to check that an item with a specific structure and values is contained in an array.
So, for example, the following works fine for me:
import { test, expect } from '@playwright/test';
test('should work', async ({ }) => {
const array = [{
success: false,
status_code: 34,
status_message: 'The resource you requested could not be found.'
}];
expect(array).toContainEqual(expect.objectContaining({
status_code: 34,
status_message: "The resource you requested could not be found.",
success: false
}));
});
Should the doc be updated to use .toEqual instead of toContainEqual?
In the doc, we actually pull issues - which is an array, so it toContainEqual
is a proper use there.
Hope this helps!
Context:
Code Snippet
Error
Describe the bug
expect.objectContaining
.expect.objectContaining
..toContainEqual(expect.objectContaining
is used..toEqual
instead oftoContainEqual
. Using.toEqual
makes the API assertion pass given one/all correct json key-value pair..toEqual
vstoContainEqual
.toEqual
- Used when you want to check that two objects have the same value. This matcher recursively checks the equality of all fields, rather than checking for object identity.toContainEqual
- Used when you want to check that an item is in a list. For testing the items in the list, this matcher recursively checks the equality of all fields, rather than checking for object identity.Query
.toEqual
instead oftoContainEqual
?