当我运行应用程序时-一切正常。但是当我运行测试时-它失败并显示错误
语法错误:意外的标识符({“对象。”:函数(模块,导出,要求,__目录名,__文件名,全局,笑话){从'../LoginPage/actions'导入操作
我的reducers.spec.js文件:
import reducer from '../LoginPage/reducers';
const state = { user: [], isLoading: false };
describe('Login reducer', () => {
it('should return initial state', () => {
expect(reducer(undefined, {})).toEqual([
{
...state,
isLoading: false
}]);
});
})
})
我的reducers.js文件:
const requestSignIn = 'REQUEST_SIGN_IN';
const receiveSignIn = 'RECEIVE_SIGN_IN';
const initialState = { user: [], isLoading: false};
export const reducer = (state, action) => {
state = state || initialState;
if (action.type === requestSignIn) {
return {
...state,
isLoading: true
};
}
if (action.type === receiveSignIn) {
return {
...state,
user: action.user,
isLoading: false
};
}
return state;
};
我尝试导入什么都没有关系。我认为完全导入是行不通的。
最佳答案
您有两种选择来解决此问题:
您需要将export const reducer
中的export default (state, action) =>
更改为reducers.js
。
要么
在reducers.spec.js
中将import reducer from '../LoginPage/reducers';
更改为import { reducer} from '../LoginPage/reducers';
有关更多信息,您可以在MDN网站上阅读有关import和export的更多信息。