// mockAxios.js
import { mockAxios } from '@ckpack/mock-axios';
mockAxios([{
url: /https:\/\/test.com\/v1\/user\/\d+/,
response: {
data: [{
id: 1,
name: 'admin',
}],
},
}]);
只需要在使用 axios 前引入该文件
import './mockAxios.js';
其他地方正常使用 axios 即可
import axios from 'axios';
await axios.get('https://test.com/v1/user/1');
// return { data: [{ id: 1, name: 'admin' }] }