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*
?
Asked
Active
Viewed 2,509 times
0

jonrsharpe
- 115,751
- 26
- 228
- 437

Javier Guzmán
- 1,014
- 2
- 13
- 27
1 Answers
5
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);

jonrsharpe
- 115,751
- 26
- 228
- 437
-
2But const url = new RegExp(`${usersUri}/*`); does create a regex that matches an arbitrary number of slashes after the userUri, it is not a wildcard match. It happens to work only because it performs an infix search. – Martin Mar 29 '21 at 11:31
-
@Martin that's true, but it is quoted from the docs. – jonrsharpe Mar 29 '21 at 11:47