It is possible to use a wildcard for the URL when mocking axios?

3k Views Asked by At

I would like to know if it is possible to mock certain URLs using wildcards, e.g. all URLs that start with /auth. Can I do something like /auth*?

1

There are 1 best solutions below

2
On BEST ANSWER

Yes, per the docs you can use a regex as the URL. One of their examples is similar to your use case:

Using variables in regex

const usersUri = '/users';
const url = new RegExp(`${usersUri}/*`);

mock.onGet(url).reply(200, users);