0
我试图用酶来测试一个阵营本地FlatList。我要检查如果有合适的函数被调用时,列表到达终点:测试阵营本地FlatList与酶
import { listIsAtTheEnd } from "./actions";
import { mount } from "enzyme";
jest.mock("./actions");
describe("Main page",() => {
if("Calls listIsAtTheEnd when FlatList reaches the end",() => {
var app = mount(<App />);
var container = app.find("FlatListContainer");
var fList = container.childAt(0);
fList.instance().scrollToEnd();
expect(listIsAtTheEnd.mock.calls).toHaveLength(1)
})
})
,但是这是我得到:
TypeError: this._scrollRef.scrollTo is not a function
at VirtualizedList.scrollToEnd (node_modules/react-native/Libraries/Lists/VirtualizedList.js:219:17)
at FlatList.scrollToEnd (node_modules/react-native/Libraries/Lists/FlatList.js:544:141)
at Object.<anonymous> (src/components/forumPage/__tests__/forumPageTests.js:81:21)
at tryCallTwo (node_modules/promise/lib/core.js:45:5)
at doResolve (node_modules/promise/lib/core.js:200:13)
at new Promise (node_modules/promise/lib/core.js:66:3)
我在做什么错?什么是测试这个的正确方法?
同意。我试着用'react-native-mock-render'来尝试使用'酶'来帮助模拟原生组件,但是我没有发现模拟的组件已经足够完成断言或快照,并最终恢复为'jest'和'react-测试renderer'。这是一个移动的目标。 React Native获得像FlatList这样的新控件,如果你要对它做任何体面的测试,它们都需要被正确地嘲笑。不是一件容易的事。 –