【发布时间】:2018-08-30 06:49:42
【问题描述】:
我正在尝试在 Jest 中使用 jsdom 来检索路径名。到目前为止我找到了这个post,其中testURL设置在package.json中
"jest": {
"testURL": "http://localhost:3000/"
}
据我所知,我不需要 jsdom 设置文件。 所以我在测试中就这样使用它:
import { jsdom, location } from 'jsdom';
it('directs to /question', () => {
const handleClick = jest.fn();
const button = shallow(
<Button handleClick={handleClick} />
);
button.find('button').simulate('click');
expect(location.href).toBe("/question")
});
当我这样做时,我总是收到错误Cannot read property 'href' of undefined。
我该如何解决这个问题?
【问题讨论】: