5

I've a very simple test

/** @jsx React.DOM */
var store = require('../simpleStore');
var TestUtils = require('react/addons').addons.TestUtils;

describe("my tests",function(){
  it('simple test',function(){
     var x=10,
        y=20;
     expect(x).not.toBe(y);
  })
})

Test works fine as long as I dont require TestUtils. The moment I add any node_module reference, I start seeing below error

Using Jest CLI v0.8.0, jasmine1
FAIL  build/stores/__tests__/simple-test.js

● Runtime Error

Error: ../stores/__tests__/simple-test.js:
../../node_modules/react/addons.js:
../../node_modules/react/lib/ReactWithAddons.js:
../../node_modules/react/lib/LinkedStateMixin.js:
../../node_modules/react/lib/ReactLink.js:
../../node_modules/react/lib/React.js:
../../node_modules/react/lib/ReactDOM.js:
../../node_modules/react/lib/ReactDOMTextComponent.js:
../../node_modules/react/lib/ReactComponentBrowserEnvironment.js:
../../node_modules/react/lib/ReactDOMIDOperations.js:
../../node_modules/react/lib/ReactMount.js:
../../node_modules/react/lib/ReactElement.js: Failed to get mock metadata:
../../node_modules/react/lib/canDefineProperty.js
npm ERR! Test failed.  See above for more details.

I'm sure a lot of people are using jest and I'm missing something silly..appreaciate any ideas to fix this issue?

Linus Oleander
  • 17,746
  • 15
  • 69
  • 102
Sahas
  • 3,046
  • 6
  • 32
  • 53

1 Answers1

5

Try to disable mocking for react - in your jset configuraction in package.json:

"unmockedModulePathPatterns": [
  "<rootDir>/node_modules/react",
  "<rootDir>/node_modules/fbjs"
]
kyrisu
  • 4,541
  • 10
  • 43
  • 66
  • Unfortunately I'm still seeing the error, even with this config: ` "unmockedModulePathPatterns": [ "/node_modules/react", "/node_modules/react-dom", "/node_modules/react-addons-test-utils", "/node_modules/fbjs" ],` – Andy Jan 31 '16 at 15:10
  • 1
    I gave up on Jest after having multiple issues with testing React-Native. You might be interested in checking out Enzyme (http://airbnb.io/enzyme/) instead. You can use Mocha and Chai for testing and it's, for the most part, painless. – kyrisu Feb 02 '16 at 06:18
  • Thanks for the tip! I ended up just using Jasmine and React TestUtils for now, but Enzyme looks great! – Andy Feb 02 '16 at 23:11
  • Did you put your "unmockedModulePathPatterns" inside the "jest" object (nested in it ?) in your json ? It don't work if you put it just under. – Maël Lavault Feb 29 '16 at 21:03