Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么Jasmine测试在Firefox中偶尔会失败_Javascript_Unit Testing_Firefox_Global Variables_Jasmine - Fatal编程技术网

Javascript 为什么Jasmine测试在Firefox中偶尔会失败

Javascript 为什么Jasmine测试在Firefox中偶尔会失败,javascript,unit-testing,firefox,global-variables,jasmine,Javascript,Unit Testing,Firefox,Global Variables,Jasmine,编辑:我将我的控制台.log更改为警报,并找到属性:getInterface 我们有一个环境完整性测试,确保我们的代码不会引入不需要的全局变量。在运行代码之前,我们创建窗口对象的“副本”: var testingWindow = {}; for (var x in window) { if (window.hasOwnProperty(x)) { testingWindow[x] = true; } } 然后在运行代码之后,我们运行以下测试: describe(

编辑:我将我的
控制台.log
更改为
警报
,并找到属性:
getInterface

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

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之外的所有浏览器中都通过。更奇怪的是,我从未见过在
控制台打开的情况下测试失败,因此任何“查看”错误的尝试都是徒劳的。感谢您的帮助


提前感谢。

这似乎是Firefox的一个错误:

当我将此条件包装在我的
expect
s上时,它们总是通过:

if (x !== 'getInterface') ...
看起来Firefox一开始并没有定义
getInterface
,后来又定义了。打开
控制台
可以在开始时对其进行定义