2013-10-11 2 views
1

У меня есть функция:В жасмин, как делает один тест функция, которая использует document.write

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

Мой жасмин тест является:

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

Моя проблема заключается в том, что тест проходит и foo document.writes на странице, полностью переписывая страницу. Есть ли хороший способ проверить эту функцию?

A related issue

ответ

4

Вы можете следить за document.write

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

describe("foo", function() { 

    it("writes bar", function() { 
    spyOn(document, 'write') 
    foo() 
    expect(document.write).toHaveBeenCalledWith('bar') 
    }); 
}); 
Смежные вопросы