我正在使用React + Redux / Redux-thunk,并且正在尝试实现玩笑/酶。我能够成功地对根组件进行通过测试。但是,我被困在试图为另一个组件制作新的测试文件的时候。无论我尝试测试哪个组件(已连接或未连接),我都会遇到相同的错误。
FAIL src/views/LoginView/LoginView.test.jsx
● Test suite failed to run
Expected the reducer to be a function.
32 | }
33 |
> 34 | const store = middleware(createStore)(rootReducer, initialState);
| ^
35 | const compressor = createCompressor();
36 | const persistor = persistStore(store, { transforms: [compressor] }, () => { store.getState(); });
37 |
at createStore (node_modules/redux/lib/createStore.js:68:11)
at node_modules/redux/lib/applyMiddleware.js:38:19
at middleware (src/redux/configureStore.js:34:17)
at Object.<anonymous> (src/main.jsx:78:37)
我什至无法编写我的第一个测试,因为它在导入组件时出错。
测试文件看起来像这样(几乎空白),并且与组件LoginView位于同一目录中。
import React from 'react';
import { shallow } from 'enzyme';
import LoginView from './LoginView';
test('passing test', () => {
});
我的jest.config.js文件如下:
module.exports = {
setupTestFrameworkScriptFile: '<rootDir>/test/setupTests.js',
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mocks__/fileMock.js',
'\\.(css|less|scss)$': 'identity-obj-proxy',
'^handsontable' : 'handsontable',
},
modulePaths: [
'<rootDir>/node_modules',
],
transformIgnorePatterns: [
'node_modules/(?!(react-joyride)/)',
],
globals: {
__API_BASE__ : '',
__HOT_BUILD_DATE__ : '',
__HOT_PACKAGE_NAME__: '',
__HOT_VERSION__ : '',
__HOT_BASE_VERSION__: '',
__BASENAME__ : false,
__DEBUG__ : false,
},
verbose: true,
};
我正在使用以下所有版本:
"react": "^16.5.2",
"babel-jest": "^23.6.0",
"jest": "^23.6.0",
"jest-enzyme": "^7.0.0",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.6.0",
"redux": "^3.7.2",
"redux-persist": "^5.5.0",
"react-redux": "^5.0.6",
"redux-raven-middleware": "^1.2.0",
"redux-thunk": "^2.2.0",
感谢您对此主题的任何反馈或指导,因为我目前无法在除根组件之外的其他组件上编写任何测试。
谢谢!