我试图在我的项目中运行测试用例,一种情况是模拟功能并验证输出。在该函数中,我使用了Toast.show()。每当我尝试通过测试用例运行该功能时,都会出现以下错误。
Cannot read property '_root' of undefined
复制步骤
在React本机组件中创建一个函数,该函数将显示Toast。编写测试用例以模拟该类并运行该函数。
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()
})
})
我也通过他们的回购报告了这个问题,看看 https://github.com/GeekyAnts/NativeBase/issues/3075