【发布时间】:2017-10-01 03:20:25
【问题描述】:
我在main.js中有以下函数(加载了node.exe):
window.onload = () => {
window.getString = function () {
<Do something>
return value;
};
}
以下是我使用 Enzyme 和 Mocha 编写的测试用例
import "jsdom-global/register";
import React from "react";
import {mount} from "enzyme";
import Sessions from "./Sessions";
describe("Testing Sessions Page", () => {
it('should work', () => {
let wrapper = mount(<Sessions/>);
});
});
在使用 React 框架编写的 Sessions 组件中,我使用 getString 方法。当我运行我的测试时,它给出了ReferenceError: getString is not defined。如何使测试代码中的窗口对象可访问?
【问题讨论】:
标签: reactjs mocha.js enzyme jsdom