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這樣的新控件,如果你要對它做任何體面的測試,它們都需要被正確地嘲笑。不是一件容易的事。 –