在 Jest 测试中 window 对象来自哪里?
In a Jest test where does the window object come from?
我有一个简单的 Jest 测试:
describe('test', function() {
beforeEach(function() {});
it('test', function() {
console.log(window.document); //a real or nearly real document
});
});
我需要一些模块,例如bootstrap - 但没有任何东西看起来像它可能会提供一个 window 对象 - 上面有一个文档对象。
我的问题是 - who/what 正在提供此 window(和 window.document)对象? window 对象类似于浏览器 window - 尽管缺少一两个方法。但我看不出是谁提供的。我不太了解 node.js 和 webpack(测试是用 webpack 构建的)不知道从哪里开始。
这不是 ReactDOM。是杰斯特吗?还是节点?
快速检查一下,我认为是 jsdom。
基于 this 博客 post:
It’s simple, standard and standalone (based on JSDom and build on top
of Jasmine).
正在查看 package.json in the jest repository、
"dependencies": {
"chalk": "^1.1.1",
"cover": "^0.2.9",
"diff": "^2.1.1",
"graceful-fs": "^4.1.3",
"istanbul": "^0.4.2",
"jest-environment-jsdom": "^12.0.2",
"jest-environment-node": "^12.0.2",
"jest-haste-map": "^12.0.2",
"jest-jasmine1": "^12.0.2",
"jest-jasmine2": "^12.0.2",
"jest-mock": "^12.0.2",
"jest-util": "^12.0.2",
"json-stable-stringify": "^1.0.0",
"lodash.template": "^4.2.4",
"mkdirp": "^0.5.1",
"optimist": "^0.6.1",
"resolve": "^1.1.6",
"sane": "^1.2.0",
"which": "^1.1.1",
"worker-farm": "^1.3.1"
},
我有一个简单的 Jest 测试:
describe('test', function() {
beforeEach(function() {});
it('test', function() {
console.log(window.document); //a real or nearly real document
});
});
我需要一些模块,例如bootstrap - 但没有任何东西看起来像它可能会提供一个 window 对象 - 上面有一个文档对象。
我的问题是 - who/what 正在提供此 window(和 window.document)对象? window 对象类似于浏览器 window - 尽管缺少一两个方法。但我看不出是谁提供的。我不太了解 node.js 和 webpack(测试是用 webpack 构建的)不知道从哪里开始。
这不是 ReactDOM。是杰斯特吗?还是节点?
快速检查一下,我认为是 jsdom。
基于 this 博客 post:
It’s simple, standard and standalone (based on JSDom and build on top of Jasmine).
正在查看 package.json in the jest repository、
"dependencies": {
"chalk": "^1.1.1",
"cover": "^0.2.9",
"diff": "^2.1.1",
"graceful-fs": "^4.1.3",
"istanbul": "^0.4.2",
"jest-environment-jsdom": "^12.0.2",
"jest-environment-node": "^12.0.2",
"jest-haste-map": "^12.0.2",
"jest-jasmine1": "^12.0.2",
"jest-jasmine2": "^12.0.2",
"jest-mock": "^12.0.2",
"jest-util": "^12.0.2",
"json-stable-stringify": "^1.0.0",
"lodash.template": "^4.2.4",
"mkdirp": "^0.5.1",
"optimist": "^0.6.1",
"resolve": "^1.1.6",
"sane": "^1.2.0",
"which": "^1.1.1",
"worker-farm": "^1.3.1"
},