reactjs - 我如何测试对象内部的函数调用?
问题描述
我有这个js文件
const apiConfig = {
addWipMappingStates: {
method: 'post',
url: env.WIP_STATES_KEY,
getResponseActions: () => {
toastr.success(`Status has been successfully added`);
return [
actions.apiCallStarted('wipMappingStates'),
actions.resetFormValue(['newWipStatesForm']),
actions.apiCallReset('addWipMappingStates'),
];
}
}
export default apiConfig
我是开玩笑和酶测试的新手。我找不到方法 - 我如何测试getResponseActions:
我的对象中的方法。
我的测试文件
我试过了
import sut from '../../constants/apiConfig';
const apiConfig = {
addWipMappingStates: {
getResponseActions: jest.fn(),
},
};
describe('apiConfig', () => {
test('addWipMappingStates', () => {
const result = sut(apiConfig);
});
});
但是当我运行时npm run test
出现错误
TypeError: (0 , _apiConfig.default) is not a function
8 | describe('apiConfig', () => {
9 | test('addWipMappingStates', () => {
> 10 | const result = sut(apiConfig);
| ^
11 | });
12 | });
我不知道如何继续这个。请帮忙
解决方案
推荐阅读
- django - Django 测试 Forms.FileField
- ajax - 函数内部的 Ajax 警报不起作用
- arrays - 如何在JS中连接Buffer数据和writeFile?
- javascript - 如何在不拆分的情况下在 javascript 函数中使用已传递到 pug 模板的数组?
- elasticsearch - 返回文档在字段中仅包含一个值
- python-3.x - 使用 pyvisa 配置 USB 设备时出错
- sql - SQL查询根据时间戳增加行值
- python - 我正在尝试更新数据库中的任务,但它不断创建新任务
- c# - 多种webapi参数绑定
- c++ - QT Creator 定义异常