From c3001c00ffbf016d406fb0e2900cd1690bcd35a9 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 13 May 2019 13:59:41 +0200 Subject: [PATCH] Proper testing of lists without order --- .../test/graphqlCrud.test.e2e.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/strapi-plugin-graphql/test/graphqlCrud.test.e2e.js b/packages/strapi-plugin-graphql/test/graphqlCrud.test.e2e.js index 11d12fb790..f310611e7c 100644 --- a/packages/strapi-plugin-graphql/test/graphqlCrud.test.e2e.js +++ b/packages/strapi-plugin-graphql/test/graphqlCrud.test.e2e.js @@ -255,10 +255,18 @@ describe('Test Graphql API End to End', () => { }); expect(res.statusCode).toBe(200); - expect(res.body).toEqual({ - data: { - posts: expected, - }, + + // same length + 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])); }); });