JavaScript In Jasmine, how does one test a function that uses document.write

I have a function:

var foo = function() {
    document.write( bar() );
};

My Jasmine test is:

describe('has a method, foo, that', function() {
    it('calls bar', function() {
        spyOn(window, 'bar').andReturn('');
        foo();
        expect(bar).toHaveBeenCalled();
    });
});

My problem is that the test passes and foo document.writes to the page, completely overwriting the page. Is there a good way to test this function?

A related issue

Answer:1

I m trying to add page number in footer this is my code var pdfInfo = {}; var x = document.location.search.substring(1).split('&'); for (var i in x) { var z = x[i].split('=',2); pdfInfo[z[...

I m trying to add page number in footer this is my code var pdfInfo = {}; var x = document.location.search.substring(1).split('&'); for (var i in x) { var z = x[i].split('=',2); pdfInfo[z[...

I'm working on an Office Add-in (formerly Apps for office) using office.js library. My app adds a handler to get notified about data changes in excel sheet: Microsoft.Office.WebExtension.select("...

I'm working on an Office Add-in (formerly Apps for office) using office.js library. My app adds a handler to get notified about data changes in excel sheet: Microsoft.Office.WebExtension.select("...

I'm using Nprogress to show a loading state for ajax requests on my Rails app. I've accomplished to make it work with all normal ajax calls but I'm now having problems with rails remote forms. I'm ...

I'm using Nprogress to show a loading state for ajax requests on my Rails app. I've accomplished to make it work with all normal ajax calls but I'm now having problems with rails remote forms. I'm ...

In my web site I need to pop up a dummy 'loading' spinning wheel when click a button and vanish after some time. It's just a dummy page. I would be much obliged if anyone can explain how to do such a ...

In my web site I need to pop up a dummy 'loading' spinning wheel when click a button and vanish after some time. It's just a dummy page. I would be much obliged if anyone can explain how to do such a ...