Supertest: expect array in any order

Created on 31 Aug 2018  路  1Comment  路  Source: visionmedia/supertest

I have something similar to this:

describe('list', () => {
  it('returns the contents of the database', async () => {
    await request
      .get('/')
      .expect(200)
      .expect(expectedItems)
  })
})

I don't care about the order (in this test) - however the test will fail if the objects in the array are not in the same order as they are in expectedItems. Is there any way to achieve this out the box or should I implement a custom expect function?

TIA

question

Most helpful comment

hello @Billy- The expect function is using the function assert.deepEqual to test the response body and the expectedItems array. deepEqual only returns true if the arrays are the same, and in the same order. If you don't care about order then you will need to implement a custom expect function.

>All comments

hello @Billy- The expect function is using the function assert.deepEqual to test the response body and the expectedItems array. deepEqual only returns true if the arrays are the same, and in the same order. If you don't care about order then you will need to implement a custom expect function.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schm1ty1 picture schm1ty1  路  4Comments

DeaconDesperado picture DeaconDesperado  路  6Comments

Shingaz picture Shingaz  路  5Comments

nareshbhatia picture nareshbhatia  路  6Comments

rkmax picture rkmax  路  5Comments