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
,后来又定义了。打开控制台
可以在开始时对其进行定义