【发布时间】:2019-05-30 19:19:54
【问题描述】:
当我运行包含有关 window.location 的逻辑的单元测试时。我会在我的终端上收到这个错误。
TypeError: window.location[(intermediate value)(intermediate value)(intermediate value)] 不是函数
35 | localVue.use(VueRouter);
> 36 | const router = new VueRouter(...routerOptions);
37 |
38 | Object.keys(filters).forEach(key => {
39 | localVue.filter(key, filters[key]);
我的示例单元测试代码仅包含有关 window.location 的逻辑
beforeEach(() => {
global.window = Object.create(window);
const url = "http://localhost.com";
Object.defineProperty(window, "location", {
value: {
href: url
},
writable: true
});
});
有人遇到过这种情况吗?在这种情况下我真的需要帮助。
【问题讨论】:
标签: unit-testing vue.js vuejs2 jestjs