无法读取未定义的本机Jest测试用例的属性'_root'

时间:2020-02-24 04:15:58

标签: reactjs react-native jestjs native-base

我试图在我的项目中运行测试用例,一种情况是模拟功能并验证输出。在该函数中,我使用了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

0 个答案:

没有答案