我们如何在Jest中访问组件const变量,酶

问题描述 投票:0回答:1
const PassengerTable = () => {
  const inFlight = window.location.pathname.includes("in-flight");
}

我们如何在测试用例中访问const inflight,以便在完成分支后更改其值为true或false。

reactjs react-native jestjs enzyme
1个回答
0
投票

您无法访问闭包内部的变量。但是您可以嘲笑它们的值来自何处:

Object.defineProperty(window.location, "pathname", {
  value: "/aaa",
  writable: true
});
const wrapper = shallow(<PassengerTable />);
expect(...)
© www.soinside.com 2019 - 2024. All rights reserved.