如何为IFrame编写Jasmine单元测试用例

时间:2014-11-13 09:18:32

标签: karma-jasmine

我正在为iframe打印编写angularJS Jasmine测试用例,但它显示"无法读取属性'打开'未定义"。请在下面找到代码片段

Source code:

$scope.print = function() {
    var iFrame = document.getElementById("printingFrame"); 
    var iFrameDoc = iFrame.contentDocument; 
    iFrameDoc.open();
    var contents = "text";
    iFrameDoc.write(contents);
    iFrameDoc.close();
    iFrame.contentWindow.focus(); 
    iFrame.contentWindow.print();
};

Test Case:

describe("just a test", function () {
    it("should print iframe content", function () {
       locals.$scope.print();
    });
});

Error:

TypeError: Cannot read property 'open' of undefined

任何人都知道为什么以下单元测试没有通过?

0 个答案:

没有答案