在Jest测试中,窗口对象来自哪里?

时间:2016-05-03 11:08:13

标签: reactjs jestjs

我有一个简单的Jest测试:

describe('test', function() {
  beforeEach(function() {});
  it('test', function() {
    console.log(window.document); //a real or nearly real document
  });
});

我需要几个模块,例如引导程序 - 但看起来它不会提供窗口对象 - 上面有文档对象。

我的问题是 - 谁/什么提供这个窗口(和window.document)对象?窗口对象类似于浏览器窗口 - 尽管缺少一两种方法。但我不知道是谁提供它。我不太了解node.js和webpack(使用webpack构建测试)以了解从哪里开始。

它不是ReactDOM。是Jest吗?还是节点?

1 个答案:

答案 0 :(得分:7)

快速检查时,我认为是jsdom

基于this博文:

  

它简单,标准和独立(基于JSDom并构建在顶部   茉莉花。)

查看package.json中的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"
  },