How to write a Jasmine unit test for an IFrame

As I write a Jasmine corner test for printing iframes, but it shows "Unable to read property" open "from undefined". Below is a snippet of code

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 

Does anyone know why the next unit test fails?

+5
source share

Source: https://habr.com/ru/post/1206784/


All Articles