https://github.com/callstack/react-native-testing-library/releases
升级到 @testing-library/react-native@8.0.0 或 @testing-library/react-native@8.0.0.rc 后,我所有的 Apollo Mocks 规范都开始失败,抛出错误 TypeError: (0 , _timers. setTimeout) 不是函数
规格示例
根据我的规范,在渲染组件后,我总是等待下一次更新或将测试包装到 waitFor 中
it("render mock title", async () => {
const { getByText } = render( <WrappedComponent />)
await act(async () => {
await new Promise(resolve => setImmediate(resolve));
});
expect(getByText("Mock title")).toBeDefined()
})
设置 React v17.0.1 React Native:0.64.2 Jest v26.6.3
笑话配置
const jestPreset = require("react-native/jest-preset");
const { defaults: tsjPreset } = require("ts-jest/presets");
...
{
...tsjPreset,
"preset": "@testing-library/react-native"
setupFiles: {
...jestPreset.setupFiles
}
}