【发布时间】:2014-12-19 09:48:03
【问题描述】:
我对 Jasmine 还很陌生,我正在尝试测试一个非常简单的场景
正在测试的代码
$(function () {
$("#add_distribution_list").click(function () {
CommonNs.Utils.setWindowLocationHRef("hello.html");
});
});
夹具
<input type='button' value='Add' id='add_distribution_list'/>
测试
describe("Distribution List Page", function () {
beforeEach(function(){
loadFixtures('button.html');
spyOn(CommonNs.Utils, 'setWindowLocationHRef');
});
it("button redirects to action2", function () {
$('#add_distribution_list').click();
expect( CommonNs.Utils.setWindowLocationHRef).toHaveBeenCalled();
});
});
结果
Expected spy setWindowLocationHRef to have been called.
My SpecRunner.html 导入 jquery、jasmine-jquery 和 CommonNs.Utils 所在的实用程序文件。
如何断言 CommonNs.Utils 上的方法已被调用?
【问题讨论】:
标签: javascript jasmine jasmine-jquery