【发布时间】:2020-06-10 03:18:56
【问题描述】:
使用 jest 运行测试时,我有基本的测试套装语法:
jest.mock('axios');
describe('app', () => {
let render
beforeEach(() => {
axiosMock.get.mockResolvedValueOnce({
data: {greeting: 'hello there'},
}),
render= renderApp()
});
test('should render something', () => {
expect(something).toBeInTheDocument();
});
});
问题是我的代码中有拦截器,当使用 jest 命令输出运行测试时:
TypeError:无法读取未定义的属性“拦截器”
并指向拦截器对象
axiosInstance.interceptors.request.use(...
axiosInstance是存储axios.create返回的变量
export const axiosInstance = axios.create({...
在 SO How do I test axios in jest 上引用了这个 axios 线程,但它不涉及任何拦截器,所以并没有真正的帮助。
【问题讨论】:
标签: reactjs jestjs axios react-testing-library