const PassengerTable = () => {
const inFlight = window.location.pathname.includes("in-flight");
}
我们如何在测试用例中访问const inflight,以便在完成分支后更改其值为true或false。
您无法访问闭包内部的变量。但是您可以嘲笑它们的值来自何处:
Object.defineProperty(window.location, "pathname", {
value: "/aaa",
writable: true
});
const wrapper = shallow(<PassengerTable />);
expect(...)