We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I use enzyme 3.10 version to snapshot test with React Native. However, I encounter this error:
this._backHandlerListener = BackHandler.addEventListener("hardwareBackPress", this.handleBackRequested); ^ TypeError: Cannot read property 'addEventListener' of undefined at SearchBar.componentDidMount SearchBar.tsx:30:49) at componentDidMount (/node_modules/enzyme/src/ShallowWrapper.js:429:22) at Object.fn [as batchedUpdates] (/node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:713:16) at new batchedUpdates (/node_modules/enzyme/src/ShallowWrapper.js:428:26) at Object.shallow (/node_modules/enzyme/src/shallow.js:10:10)
This is the code that cause the crash:
const search = ( <SearchBar cancelSearch={cancelSearchSpy} searchApps={searchAppsSpy} /> ); const wrapper = shallow(search)
This line of code shouldn't crash the test suite.
The text was updated successfully, but these errors were encountered:
To test React Native properly, you'd need a React Native adapter (enzyme-adapter-react-16 is for react-dom).
Track #1436 for that.
Specific to your OP, however, the implication is that BackHandler is undefined. Is this something RN provides? If so, you'd have to mock it.
BackHandler
Sorry, something went wrong.
RN is providing this. However I suspect this is a native module. I manage to overcome this bug by mocking BackHandler:
BackHandler.addEventListener = jest.fn(// your function here)
To test with RN, you'd have to ensure all the RN things are available in node.
No branches or pull requests
Current behavior
I use enzyme 3.10 version to snapshot test with React Native. However, I encounter this error:
This is the code that cause the crash:
Expected behavior
This line of code shouldn't crash the test suite.
Your environment
API
Version
Adapter
The text was updated successfully, but these errors were encountered: