1

编辑:我将我的更改console.log为 analert并找到了属性:getInterface.

我们有一个环境完整性测试,以确保我们的代码不会引入不需要的全局变量。在运行我们的代码之前,我们创建一个对象的“副本” window

var testingWindow = {};
for (var x in window) {
    if (window.hasOwnProperty(x)) {
        testingWindow[x] = true;
    }
}

然后在运行我们的代码之后,我们运行这个测试:

describe('After the program has run', function() {
    it('no new global variables have been introduced', function() {
        for (var x in window) {
            if (window.hasOwnProperty(x)) {
                if (!testingWindow[x]) {
                    console.log(x);
                }
                expect(testingWindow[x]).not.toBe(undefined);
                expect(window.hasOwnProperty(x)).toBe(true);
            }
        }
    });
});

该测试在除 Firefox 之外的所有浏览器中均通过。更奇怪的是,我从未见过console打开时测试失败,所以任何“看到”错误的尝试都是徒劳的。任何帮助表示赞赏。

提前致谢。

4

1 回答 1

2

这似乎是一个 Firefox 错误:https ://github.com/visionmedia/mocha/issues/380 。

当我将这个条件包裹在我expect的 s 周围时,它们总是通过:

if (x !== 'getInterface') ...

看起来 FirefoxgetInterface一开始没有定义,后来才定义。console打开使其在开始时定义。

于 2013-10-31T14:54:55.190 回答