Closed MrBr closed 3 years ago
Good point.
I'm not a normal jest user, but the reason I made this a require
call and not an import
statement is the import
statement will run before the jest.dontMock(...)
call.
Will this properly not get mocked by jest still?
To be honest I was just testing different test frameworks, so I am not "big" jest user myself.
I ran few tests, it seems it is the same, however if I comment dontMock
function it also doesn't have any impact on the outcome (in any scenarios, import or require), not sure why component didn't get mocked when removed dontMock
.
Anyway, the error thrown is cos you are using export default Foo
at component definition and importing it with require
. I can change pull request to export Foo with module.exports = Foo
, and revert current change.
This'll all be fixed in jest 0.9. @lelandrichardson we should probably chat about this and simplify the setup. Jest 0.9 will likely work much better with enzyme together – would you be willing to help add this example (in a working state against 0.9 :) ) to the jest repo directly?
+1
Using require to get react component throws error.
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). Warning: Failed propType: Invalid prop
Component
supplied to<<anonymous>>
. 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 (1.376s) ● A suite › it contains spec with an expectation