axios-mock-adapter
axios-mock-adapter copied to clipboard
passing matched regex groups in config
What about storing regex matches into the config object:
const getUser = (id) => [
1: { name: 'Vladimir' },
2: { name: 'Donald' },
](id)
mock
.onGet(/\/api\/user\/(\d+)/) // path: '/api/user/1'
.reply(config => {
const id = config.matches[1]
[200, getUser(id)]
})
mock
.onGet(/\/api\/user\/(\d+)\/gun\/(\d+)/) // path: '/api/user/1/gun/2'
.reply(config => {
const gunId = config.matches[2]
[200, getUserGun(gunId)]
})
so we can do advanced mocking according to route parameters