Skip to content Skip to sidebar Skip to footer

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() {

Solution 1:

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')
  });
});

Post a Comment for "In Jasmine, How Does One Test A Function That Uses Document.write"