我正在尝试测试一个包含子组件的组件,该子组件包含 react-intersection-observer 但我总是收到错误
我试图导入库,但它仍然失败。这是初步测试
beforeEach(() => {
testContainer = document.createElement("div");
document.body.appendChild(testContainer);
subject = memoize(() =>
mount(<FilterNav {...props} />, { attachTo: testContainer })
);
});
afterEach(() => {
testContainer.remove();
});
context("the main filter is shown initially", () => {
it("sets focus on the primary filter", () => {
subject();
const input = testContainer.querySelector(".main-input");
expect(document.activeElement).toEqual(input);
});
我收到此错误 -> Uncaught [ReferenceError: IntersectionObserver is not defined]
有什么方法可以模拟 IntersectionObserver 吗?
谢谢
原文由 Rafael Simões 发布,翻译遵循 CC BY-SA 4.0 许可协议
我实际上能够通过模拟函数解决这个问题并将其包含在窗口对象中