ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.47k stars 245 forks source link

Add full URL with serialized query parameters to history #311

Open sean256 opened 3 years ago

sean256 commented 3 years ago

I've run into a case where I needed to customize axio's paramsSerializer to change the default handling of array serialization.

It would be super if we could test for proper param serialization with this mock adapter.

My suggestion would be to add a new fullUrl to the history entries which includes the serialized parameters.

bdsoha commented 1 year ago

@sean256 I second that!

bdsoha commented 1 year ago

After a second look, I noticed that the history object is returning a native axios object that does not have a fullUrl equivalent parameter.

https://github.com/ctimmerm/axios-mock-adapter/blob/37a2875003155b8a7013563efb3e8090cd457b60/types/index.d.ts#L64

Solution

Instead of basing my tests on the generated output of a custom paramsSerializer, I added assertions for the params passed in object form to the request.

In addition, I extracted the value of the paramsSerializer function and separately added a full series of tests at the unit-level.