Javascript 在FaceBookCubitor/create react应用程序中编写测试
我现在第一次学习ReactJS 从Javascript 在FaceBookCubitor/create react应用程序中编写测试,javascript,reactjs,Javascript,Reactjs,我现在第一次学习ReactJS 从 锅炉板:facebookinclator/create react应用程序 使用以下方法进行测试:npm测试 我决定不使用普通的在线网站进行练习的主要原因是因为我想尽可能熟悉真正的工具。 这是我的密码 export const counter = (state = 0, action) => { switch (action.type) { case 'INCREMENT': return state + 1; case
锅炉板:
facebookinclator/create react应用程序
使用以下方法进行测试:
npm测试
我决定不使用普通的在线网站进行练习的主要原因是因为我想尽可能熟悉真正的工具。
这是我的密码
export const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
还有我的utils.test.js
import React from 'react';
import counter from '../utils/utils';
it('expect 1 to be return from reducer', () => {
expect(counter(0, {type: 'INCREMENT'})).toEqual(1)
});
错误: FAIL src/utils/utils.test.js
● expect 1 to be return from reducer
TypeError: (0 , _utils2.default) is not a function
at Object.<anonymous>.it (src/utils/utils.test.js:5:30)
at new Promise (<anonymous>)
at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
PASS src/App.test.js
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time: 0.062s, estimated 1s
Ran all test suites.
Watch Usage: Press w to show more.
失败src/utils/utils.test.js
● 期望1从减速器返回
TypeError:(0,_utils2.default)不是函数
在对象处。看起来您的计数器是命名导入,而不是默认导入
尝试使用此选项导入计数器
:
import { counter } from '../utils/utils';
只有将计数器
导出为utils
模块的默认值时,当前使用的语法才有效 请等3分钟。非常感谢您的快速回复。