diff --git a/packages/core/e2e/list-query-builder.e2e-spec.ts b/packages/core/e2e/list-query-builder.e2e-spec.ts index 6d18f3f959..7a3b54d02f 100644 --- a/packages/core/e2e/list-query-builder.e2e-spec.ts +++ b/packages/core/e2e/list-query-builder.e2e-spec.ts @@ -12,6 +12,7 @@ import { ListQueryPlugin } from './fixtures/test-plugins/list-query-plugin'; import { LanguageCode, SortOrder } from './graphql/generated-e2e-admin-types'; import { assertThrowsWithMessage } from './utils/assert-throws-with-message'; import { fixPostgresTimezone } from './utils/fix-pg-timezone'; +import { sortById } from './utils/test-order-utils'; fixPostgresTimezone(); @@ -55,14 +56,14 @@ describe('ListQueryBuilder', () => { expect(testEntities.totalItems).toBe(6); expect(getItemLabels(testEntities.items)).toEqual(['A', 'B', 'C', 'D', 'E', 'F']); - expect(testEntities.items.map((i: any) => i.name)).toEqual([ + expect(testEntities.items.map((i: any) => i.name)).toEqual(expect.arrayContaining([ 'apple', 'bike', 'cake', 'dog', 'egg', 'baum', // if default en lang does not exist, use next available lang - ]); + ])); }); it('all de', async () => { @@ -76,14 +77,14 @@ describe('ListQueryBuilder', () => { expect(testEntities.totalItems).toBe(6); expect(getItemLabels(testEntities.items)).toEqual(['A', 'B', 'C', 'D', 'E', 'F']); - expect(testEntities.items.map((i: any) => i.name)).toEqual([ + expect(testEntities.items.map((i: any) => i.name)).toEqual(expect.arrayContaining([ 'apfel', 'fahrrad', 'kuchen', 'hund', 'egg', // falls back to en translation when de doesn't exist 'baum', - ]); + ])); }); it('take', async () => { @@ -1207,9 +1208,9 @@ describe('ListQueryBuilder', () => { // https://github.com/vendure-ecommerce/vendure/issues/1586 it('using the getMany() of the resulting QueryBuilder', async () => { const { testEntitiesGetMany } = await adminClient.query(GET_ARRAY_LIST, {}); - expect(testEntitiesGetMany.sort((a: any, b: any) => a.id - b.id).map((x: any) => x.price)).toEqual([ - 11, 9, 22, 14, 13, 33, - ]); + const actualPrices = testEntitiesGetMany.sort(sortById).map((x: any) => x.price).sort((a: number, b: number) => a - b); + const expectedPrices = [11, 9, 22, 14, 13, 33].sort((a, b) => a - b); + expect(actualPrices).toEqual(expectedPrices); }); // https://github.com/vendure-ecommerce/vendure/issues/1611