ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.45k stars 244 forks source link

Support response header #379

Closed Caellian closed 6 months ago

Caellian commented 11 months 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 6 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 6 months ago

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