Reputation: 8279
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?
Upvotes: 2
Views: 4241
Reputation: 111062
You can spy on document.write
var foo = function () {
document.write('bar');
};
describe("foo", function () {
it("writes bar", function () {
spyOn(document, 'write')
foo()
expect(document.write).toHaveBeenCalledWith('bar')
});
});
Upvotes: 6