TypeError:(0,_helper.addValue)不是一个函数Jest错误

时间:2018-11-13 06:11:11

标签: javascript reactjs npm jestjs babel-jest

即使在指定文件中定义了函数,开玩笑也给出了函数未定义的错误。我正在测试cards.js中定义的功能,但是当我使用'npm运行测试时,开玩笑地也在执行我的reducer文件 测试”,这在reducer文件中给出了一个错误,该错误未定义fun,但该功能在helper.js中定义,并且在我运行我的应用程序时也可以正常运行。它只会在npm测试控制台中显示错误。

错误:●测试套件无法运行 TypeError:(0,_helper.addValue)不是一个函数

helper.js

export const addValue = (a, b) => a+ b

filter.reducer.js

import {addValue} from '../helper';
const result = addValue(5,4);
.
.
.
.

cards.js

import {pipe, prop} from 'ramda'
exprot const transformCardData = (response) =>{
  if(isEmpty(response)){
    return {}
   }
  return pip(
         prop('values)
       )
      }

` cards.test.js

describe('testing transformCardData function ', ()=>{
  it('testing empty response',()=>{
    expect(transformCardData({})).toBe({})
 }
}

package.json开玩笑的配置

"scripts": {
    "analyze": "source-map-explorer build/static/js/main.*",
    "start": "node scripts/start.js",
    "build": "NODE_ENV='production' GENERATE_SOURCEMAP=false node scripts/build.js",
    "test": "node scripts/test.js"
  },
  "jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,mjs}"
    ],
    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
      "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
    ],
    "testEnvironment": "node",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web"
    },
    "moduleDirectories": [
      "node_modules",
      "src"
    ],
    "moduleFileExtensions": [
      "web.js",
      "mjs",
      "js",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ]
  },
"devDependencies": {
    "babel-jest": "20.0.3",
    "jest": "^23.6.0",
    "jest-cli": "^23.6.0",
.
.
.
}

test.js

'use strict';

// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'test';
process.env.NODE_ENV = 'test';
process.env.PUBLIC_URL = '';

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
  throw err;
});

// Ensure environment variables are read.
require('../config/env');

const jest = require('jest');
const argv = process.argv.slice(2);

// Watch unless on CI or in coverage mode
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
  argv.push('--watch');
}


jest.run(argv);

0 个答案:

没有答案