窗口未定义jsdom和jasmine-node

时间:2012-11-10 19:12:03

标签: javascript testing jasmine jsdom jasmine-node

我有一个文件runspecs.js初始化一些全局对象,如窗口和文档

//fake browser window & document
jsdom = require("jsdom");
global.document = jsdom.jsdom("<html><body></body></html>", jsdom.level(1, "core"));
global.window = jsdom.jsdom().createWindow();
global.jQuery = require("jquery");

global.document.cookie = '';

//Test framework
var jasmine=require('jasmine-node');
for(var key in jasmine) {
  global[key] = jasmine[key];
}

//What we're testing
//Make sure the coffeescript is compiled!

global.Socrates = require("./src/socrates.js").Socrates;

jasmine.executeSpecsInFolder(__dirname + '/specs', function(runner, log){
    process.exit(runner.results().failedCount?1:0);
}, true, true);

现在我在specs目录下的唯一文件是socrates.spec.coffee及其编译文件socrates.spec.js:

testNode = jQuery("<a id='testNode class='socrates' data-entity-id='bubbles'").appendTo('body')

describe 'socrates.js', () ->
  describe 'document/window setup', () ->
    it 'is attaches an instance to the window', () ->
      soc = new Socrates([])
      expect(window.socrates.prototype).toEqual(soc.prototype)

既然新的苏格拉底没有失败,我们知道至少全球的苏格拉底正在经历。它使用document和document.cookie,所以那些也没关系。为什么窗口未定义?

0 个答案:

没有答案