enzyme-example-jest icon indicating copy to clipboard operation
enzyme-example-jest copied to clipboard

Jest tests ?

Open note89 opened this issue 8 years ago • 4 comments

All your tests are commented out, is this the official example ? https://github.com/lelandrichardson/enzyme-example-jest/blob/master/src/tests/Foo-test.js

note89 avatar Mar 23 '16 18:03 note89

Uncommenting jest tests (shallow render) throws this error:

Using Jest CLI v0.8.2, jasmine1 Running 1 test suite...Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). FAIL src/tests/Foo-test.js (0.912s) ● A suite › it contains spec with an expectation

  • TypeError: Component is not a function at StatelessComponent.render (node_modules/react/lib/ReactCompositeComponent.js:44:10) 1 test failed, 2 tests passed (3 total in 1 test suite, run time 1.269s) npm ERR! Test failed. See above for more details.

zuhair-naqvi avatar May 31 '16 00:05 zuhair-naqvi

Seems like there are problems with Jest and Enzyme :( https://github.com/facebook/jest/issues/1175

calclavia avatar Jun 26 '16 06:06 calclavia

This can be solved updating jest-cli and using "import Foo from "./Foo" and use "jest.unmock()" instead of jest.dontMock() https://facebook.github.io/jest/docs/api.html#jest-unmock-modulename

Madalosso avatar Jul 28 '16 13:07 Madalosso

I still get errors when trying to add uncomment mount test. I updated jest-cli to version 17.0.0 + I changed to jest.unmock('../Foo');

I get the following error:

src/tests/Foo-test.js Console

console.error node_modules/fbjs/lib/warning.js:45
  Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).
console.error node_modules/fbjs/lib/warning.js:45
  Warning: Failed propType: Invalid prop `Component` supplied to `<<anonymous>>`.

A suite › contains spec with an expectation

TypeError: ReactDOM.render is not a function

  at Object.ReactTestUtils.renderIntoDocument (node_modules/react/lib/ReactTestUtils.js:76:21)
  at Object.<anonymous> (src/__tests__/Foo-test.js:19:30)

cc @Madalosso

yanivefraim avatar Nov 10 '16 22:11 yanivefraim