在Jasmine中,如何测试使用document.write的功能 [英] In Jasmine, how does one test a function that uses document.write
本文介绍了在Jasmine中,如何测试使用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到页面,完全覆盖了页面.有没有测试此功能的好方法?
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?
推荐答案
您可以监视document.write
var foo = function () {
document.write('bar');
};
describe("foo", function () {
it("writes bar", function () {
spyOn(document, 'write')
foo()
expect(document.write).toHaveBeenCalledWith('bar')
});
});
这篇关于在Jasmine中,如何测试使用document.write的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文