I am trying to run testcases in my project, one scenario is to mock the function and validate output. In that function I have used Toast.show(). Whenever I am trying to run that function through testcases, it gives me below error.
Cannot read property '_root' of undefined
Steps to reproduce
Create a function in React native component which will show Toast. Write test case to mock that class and run that function.
First.test.js
describe("Dashboard Component", () => {
it("should call onFunctionCall", () => {
const wrapper = shallow(
<Dashboard navigation={navigation} />
).dive().dive().dive().dive()
const onFunctionCall = jest.spyOn(wrapper.instance(), "onFunctionCall")
wrapper.update()
wrapper.instance().forceUpdate()
wrapper.instance().onFunctionCall()
expect(onFunctionCall).toHaveBeenCalled()
})
})
I have reported this issue over their repo also, take a look https://github.com/GeekyAnts/NativeBase/issues/3075