如何使用路由参数模拟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);发布于 2017-12-08 10:30:30
将占位符转换为通配符,并将路径转换为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);https://stackoverflow.com/questions/46954860
复制相似问题