单元测试与jest 0.4.0和节点0.12.0反应

时间:2016-03-23 14:46:40

标签: node.js unit-testing reactjs jestjs

我正在尝试为具有单选按钮的简单反应组件编写单元测试。测试是否失败是不重要的,因为我在测试可以完成其工作之前遇到语法错误。 我正在运行React0.14.7,node0.12.0和jest 0.4.0(此版本的jest与node0.12.0兼容。我的依赖项列在下面。

"devDependencies": {
"babel-jest": "^9.0.3",
"babel-polyfill": "^6.7.2",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"gulp": "latest",
"gulp-concat": "latest",
"gulp-less": "latest",
"gulp-react": "latest",
"gulp-sourcemaps": "latest",
"jest-cli": "^0.4.0",
"watch": "latest"
},
"jest": {
  "scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"testFileExtensions": ["es6", "js"],
"moduleFileExtensions": ["js", "json", "es6"]

}

这是我的测试“../ src / 测试 /radio-group-test.js”

jest.unmock('../components/radio-group.jsx')

import React from 'react'
import ReactDOM from 'react-dom'
import TestUtils from 'react-addons-test-utils'
import PolicyConditions from '../components/radio-group.jsx'

describe('../components/radio-group.jsx', () => {
  it('renders a subform when clicking a checkbox', () => {
    var conditions = TestUtils.renderIntoDocument(
      <RadioGroup 
        radioType='labelRadios'
        name='email'
      />
    )

    var radioNode = ReactDOM.findDOMNode(radio)

    expect(radioNode.checked).toEqual('false')

    TestUtils.Simulate.change(
      TestUtils.findRenderedDOMComponentWithTag(radio, 'checked')
    )

    expect(radioNode.checked).toEqual('true')
  })
})

来自终端的错误:

SyntaxError: ../node_modules/babel-jest: ../node_modules/babel-jest/src/index.js:15
process(src, filename) {
       ^ 
Unexpected token (

它几乎就像babel在翻译es2015时所做的工作一样,因为在将const更改为var之前使用'use strict'; var babel = require('babel-core'); var jestPreset = require('babel-preset-jest'); module.exports = { process(src, filename) { if (babel.util.canCompile(filename)) { return babel.transform(src, { auxiliaryCommentBefore: 'istanbul ignore next', filename, presets: [jestPreset], retainLines: true, }).code; } return src; }, }; 时出现了错误。

编辑:道歉,忘了添加实际失败的代码。

controller_action_predispatch_checkout_onepage_index

0 个答案:

没有答案