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, pletely overwriting the page. Is there a good way to test this function?
A related issue
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, pletely overwriting the page. Is there a good way to test this function?
A related issue
Share Improve this question edited May 23, 2017 at 12:06 CommunityBot 11 silver badge asked Oct 11, 2013 at 14:16 jdsjds 8,28013 gold badges68 silver badges111 bronze badges1 Answer
Reset to default 6You 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')
});
});