ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.44k stars 241 forks source link

Adding multiple expect.objectContaining, overrides each other #323

Open ghost opened 2 years ago

ghost commented 2 years ago

When adding multiple different handlers, last one overrides previous ones:

// this one is overridden 
httClientMock.onPost('/table', expect.objectContaining({ sortModel: [] }))
   .reply(200, mockTableData);
// this one is the only one registered at the end
httClientMock.onPost('/table', expect.objectContaining({ sortModel: [{ sort: 'asc', colId: '1' }] }))
   .reply(200, mockTableData2);

Actual: In this example if request is done with sortModel: []. Axios will respond with not found error.

Expected: Request with sortModel: [] responds with mockTableData

By debugging found out that in lib sources findInHandlers -> utils.isEqual(item[1], handler[1]) returns true for different jest marchers.

By the way works as expected if I just use { asymmetricMatch: ... }