ctimmerm / axios-mock-adapter

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

Support response header #379

Closed Caellian closed 8 months ago

Caellian commented 1 year ago

In order to mock auth route I need to provide a custom header in the reponse that's returned by the server.

As far as I can tell, only body of the response can be specified neither documentation gives details on this nor have I been able to figure it out by looking at the sources.

If it's already supported could you provide an example of modifying response headers?

kbublitz commented 8 months ago

The documentation is not very clear about this, but you can pass headers as a third argument to the reply method

mock.onGet("/users").reply(
    200,
    {
        users: [{ id: 1, name: "John Smith" }],
    },
    { "Content-Type": "application/json" },
);

Hope this helps.

Caellian commented 8 months ago

That seems to be what I wanted to do at the time.