You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to match specific data and params in an onPut handler.
The docs mention this:
Mocking a request with a specific request body/data mock.onPut('/product', { id: 4, name: 'foo' }).reply(204);
Mocking a GET request with specific parameters mock.onGet('/users', { params: { searchText: 'John' } }).reply(200, {...})
So, it's possible to match params for get requests, and data for put and post. But this test case shows that it's not possible to match params in onPut.
it("can't pass query params for put to match to a handler",function(){mock.onPut('/withParams',{params: {foo: 'bar',bar: 'foo'}}).reply(200);returninstance.put('/withParams',{params: {bar: 'foo',foo: 'bar'},in: true}).catch(function(error){expect(error.response.status).to.equal(404);});});
Specifically, something like this would be convenient: mock.onPut('/users', { params: { userId: '123' }, data: { userName: 'new userName' }}),
or mock.onPut('/users', { userName: 'new userName' }, { userId: '123' })
I achieved something equivalent with mock.onAny().reply(), which works well with jest.
I would like to match specific data and params in an
onPut
handler.The docs mention this:
So, it's possible to match params for
get
requests, and data forput
andpost
. But this test case shows that it's not possible to match params inonPut
.Specifically, something like this would be convenient:
mock.onPut('/users', { params: { userId: '123' }, data: { userName: 'new userName' }})
,or
mock.onPut('/users', { userName: 'new userName' }, { userId: '123' })
I achieved something equivalent with
mock.onAny().reply()
, which works well with jest.But this is a bit convoluted, I have to manually check the url, params, parse the data, etc...
Is there a reason why this isn't or can't be implemented ? Otherwise, I'd be happy to work on a solution.
The text was updated successfully, but these errors were encountered: