Invariant Violation: Element type is invalid
See original GitHub issueExpected behavior
When I test with enzyme using shallow render - I should be able to .find(‘DatePicker’) but it returns 0 results. - trying with mount() throws an error
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
and that error is on the mount itself before I even try to find it
Actual behavior
Steps to reprodcue
the components under test
<div className='l-flex l-flex-c t-field t-field-pad'>
<label>
LMP
</label>
<i className='t-sep'/>
<span className='t-validation-wrap l-fg1'>
<DatePicker
locale={'he-IL'}
className='t-field-text w100 t-field--date'
selected={this.state.selectedDate ? moment(this.state.selectedDate) : null}
onChange={this._setDate}
/>
</span>
</div>
Issue Analytics
- State:
- Created 5 years ago
- Comments:11
Top Results From Across the Web
Uncaught Error: Invariant Violation: Element type is invalid ...
This error can rise if you try to import a non-existent component. Make sure you have no typo and that the component indeed...
Read more >Invariant Violation: Element type is invalid: expected a ...
Invariant Violation : Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Read more >(React) Element type is invalid, expected a string (for built ...
To solve the error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got",...
Read more >Invariant Violation: Element type is invalid ... - YouTrack
Invariant Violation : Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >Error Invariant Violation Element type is invalid expected a ...
Error Invariant Violation Element type is invalid expected a string for built-in components or a class function but got object.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Changing import to
const DatePicker = require('react-datepicker');
worked for me and I can launch tests using jest + enzyme.However, with this change the application cannot launch and now I’m getting this error in the console:
Thanks to a coworker pointing this thread out, the
expected a string (for built-in components) or a class/function (for composite components) but got: object
error we had was resolved with the following:Old
New