Proper testing of lists without order

This commit is contained in:
Alexandre Bodin 2019-05-13 13:59:41 +02:00
parent 89594ea416
commit c3001c00ff

View File

@ -255,10 +255,18 @@ describe('Test Graphql API End to End', () => {
}); });
expect(res.statusCode).toBe(200); expect(res.statusCode).toBe(200);
expect(res.body).toEqual({
data: { // same length
posts: expected, expect(res.body.data.posts.length).toBe(expected.length);
},
// all the posts returned are in the expected array
res.body.data.posts.forEach(post => {
expect(expected).toEqual(expect.arrayContaining([post]));
});
// all expected values are in the result
expected.forEach(expectedPost => {
expect(res.body.data.posts).toEqual(expect.arrayContaining([expectedPost]));
}); });
}); });