【发布时间】:2021-09-13 16:23:59
【问题描述】:
如何使用 sinon 模拟这个 axios 导入,然后使用期望?我试过了:
import axios from 'axios';
axiosMock = sinon.mock(axios);
但期望失败:
describe('Random test', () => {
it('should run the test', async () => {
axiosMock.withArgs(sinon.match.any).once();
await getName();
}
}
被测函数是:
import axios, { AxiosRequestConfig } from 'axios';
async function getName() {
const config: AxiosRequestConfig = {
method: 'GET',
url: ' someUrl',
headers: {},
};
const res = await axios(config);
return res;
}
【问题讨论】:
-
您使用的是什么测试runner?
jest、mocha、ava,还有别的吗?
标签: typescript mocking sinon