Я тестирую React, приложение Redux с Jest.Jest test хорошо работает с простым функциональным тестом.но тест создателя действия завершается неудачно и выдает сообщение об ошибке ниже.Это рабочий код создателя.Отправка этого создателя действия в компонент обновляет состояние.
TypeError: (0 , _reserve.saveReserveInfo) is not a function
5 | const id = 'date';
6 | const value = '2018-09-30';
> 7 | const action = saveReserveInfo(id, value);
| ^
8 | expect(action).toEqual({
9 | type: types.SAVE_RESERVE_INFO,
10 | id: 'date',
actionTypes.js
module.exports = {
SAVE_RESERVE_INFO: 'SAVE_RESERVE_INFO',
OPEN_RESERVE: 'OPEN_RESERVE',
};
reserve.action.js
import * as types from '../actionTypes';
export const saveReserveInfo = (id, value) => {
return {
type: types.SAVE_RESERVE_INFO,
id,
value,
};
};
export const openReserve = () => ({
type: types.OPEN_RESERVE,
});
reserve.test.js
import * as types from '../../components/actionTypes';
import { saveReserveInfo } from '../../components/reserve/reserve.action';
test('should create an action to update reserve info', () => {
const id = 'date';
const value = '2018-09-30';
const action = saveReserveInfo(id, value);
expect(action).toEqual({
type: types.SAVE_RESERVE_INFO,
id: 'date',
value: '2018-09-30',
});
});
клиент/jest.config.js
module.exports = {
displayName: 'client',
setupTestFrameworkScriptFile: require.resolve(
'../test/setup-test-framework.js',
),
modulePaths: ['<rootDir>/src'],
moduleNameMapper: {
'\\.scss||css$': require.resolve('../test/style-mock.js'),
'\\.svg$': require.resolve('../test/svg-file-mock.js')
},
};
jest.config.js
module.exports = {
testMatch: ['**/__test__/**'],
testPathIgnorePatterns: ['/node_modules/'],
coverageDirectory: './coverage',
collectCoverageFrom: [
'**/src/**/*.js',
'!**/__test__/**',
'!**/node_modules/**',
],
coverageThreshold: {
global: {
statements: 18,
branches: 10,
functions: 19,
lines: 18,
},
},
projects: ['./client', './server'],
};
babelrc.js
const isTest = String(process.env.NODE_ENV) === 'test';
module.exports = {
presets: [
[
'env',
{
targets: {
browsers: ['last 2 versions', 'safari >= 7'],
node: 'current',
},
loose: true,
modules: isTest ? 'commonjs' : false,
debug: isTest ? false : true,
},
],
'react',
],
retainLines: true,
plugins: [
[
'transform-runtime',
{
helpers: false,
polyfill: false,
regenerator: true,
moduleName: 'babel-runtime',
},
],
'transform-class-properties',
'transform-object-rest-spread',
'syntax-dynamic-import',
isTest ? 'dynamic-import-node' : null,
].filter(Boolean),
env: {
development: {
plugins: ['react-hot-loader/babel'],
},
},
};
версия
jest: 23.5.0,
jest-dom: 1.12.0,
react: 16.4.2,
react-dom: 16.4.2,
react-redux: 5.0.7,
redux: 4.0.0,
Вот файл zip проекта. Спасибо !!