enzyme-example-jest
enzyme-example-jest copied to clipboard
Jest tests ?
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
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.
Seems like there are problems with Jest and Enzyme :( https://github.com/facebook/jest/issues/1175
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
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