React Jest example not working

Trying to run the Jest test sample response code (from https://github.com/facebook/jest/tree/master/examples/react ), I get the following error:

  > @ test /home/aizquier/jest/examples/react
  > jest

  Using Jest CLI v0.7.1
   FAIL  __tests__/CheckboxWithLabel-test.js 
  ● Runtime Error
  SyntaxError: /home/aizquier/jest/examples/react/__tests__/CheckboxWithLabel-test.js: Unexpected token (15:6)
  npm ERR! Test failed.  See above for more details.

Tests are not performed on line 15 of the CheckboxWithLabel-test.js file:

jest.dontMock('../CheckboxWithLabel');

import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';

const CheckboxWithLabel = require('../CheckboxWithLabel');

describe('CheckboxWithLabel', function() {

  it('changes the text after click', function() {

    // Render a checkbox with label in the document
    var checkbox = TestUtils.renderIntoDocument(
      <CheckboxWithLabel labelOn="On" labelOff="Off" />
    );

    var checkboxNode = ReactDOM.findDOMNode(checkbox);

    // Verify that it Off by default
    expect(checkboxNode.textContent).toEqual('Off');

    // Simulate a click and verify that it is now On
    TestUtils.Simulate.change(TestUtils.findRenderedDOMComponentWithTag(checkbox, 'input'));
    expect(checkboxNode.textContent).toEqual('On');
  });

});

obviously the preprocessor for handling .jsx is not working. The .json package is as follows:

{
  "dependencies": {
    "react": "~0.14.0",
    "react-dom": "~0.14.0"
  },
  "devDependencies": {
    "react-addons-test-utils": "~0.14.0",
    "babel-jest": "*",
    "jest-cli": "*"
  },
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "scriptPreprocessor": "./node_modules/babel-jest",
    "unmockedModulePathPatterns": [
      "./node_modules/react",
      "./node_modules/react-dom",
      "./node_modules/react-addons-test-utils",
      "./node_modules/fbjs"
    ]
  }
}

My node is v4.2.2 and npm is 3.3.12.

Any ideas?

+4
source share
2 answers

. , , Babel 6. , , , !

babel-jest package.json. , ^5.3.0.

+6

Babel 6, , . , 'package.json', '.babelrc' 'response' 'es2015' . . http://babeljs.io/docs/plugins/preset-react/

+2

All Articles