如何使用route params模拟http请求?
var axios = require('axios');
var MockAdapter = require('axios-mock-adapter');
// This sets the mock adapter on the default instance
var mock = new MockAdapter(axios);
mock.onGet('/api/colleges/:collegeId/branches/:branchesId').reply(200);
答案 0 :(得分:0)
将占位符转换为通配符和RegExp的路径:
function route (path = '') {
return typeof path === 'string'
? new RegExp(path.replace(/:\w+/g, '[^/]+'))
: path
}
像这样使用:
mock.onGet(route('/api/colleges/:collegeId/branches/:branchesId')).reply(200);