如何解决开玩笑的测试:无法读取未定义的属性“状态”
我正在尝试使用Axios get请求测试功能。当我收到响应时,我正在调用另一个函数来过滤JSON文档。
// sample.js
import axios from "axios";
public async getFruitData{
const response = await axios.get("https://api.url.com/search/fruit",{
params: {
client_id: process.env.REACT_APP_UNSPLASH_TOKEN,query: term
}
});
return this.filtersResponse(response.data.results); //<---throwing error
};
filterResponse(detailsResponse) {
const excludeFruit = ['apple'];
return detailsResponse.filter(record => !excludeFruit.includes(record.fruit_type));
}
这是我的笑话
import axios from 'axios';
import Fruit from '../app/fruit';
jest.mock('axios');
test('it filter jsont fruit ',async () => {
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: 'test' }));
const result = await getFruitData();
expect(result).toBe({"data": "test"});
expect(filterResponse(record)).toBeDefined()
});
运行测试时,它给了我以下错误-> TypeError: Cannot read property 'status' of undefined
如何测试这种情况
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。