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

jay*_*abu 7 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
Run Code Online (Sandbox Code Playgroud)

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