admin管理员组文章数量:1307837
I'm writing specs for different test cases for Jasmine and QUnit to pare them and they looked the same before I needed to write a test to check if an event is binded to an element.
Event binding looks like
$('.page').live('click', function() { page_clicked( $(this) ) });
page_clicked
is a private method but it calls for a public method of another module.
Here is a Jasmine spec:
it('should bind events to pages', function() {
spyOn( search, 'get_results' );
$('.page:eq(0)').trigger('click');
expect( search.get_results ).toHaveBeenCalled();
});
This test works. Now I'm trying to write the same test for QUnit and can't find anything similar to spyOn. How to write this test for QUnit?
I'm writing specs for different test cases for Jasmine and QUnit to pare them and they looked the same before I needed to write a test to check if an event is binded to an element.
Event binding looks like
$('.page').live('click', function() { page_clicked( $(this) ) });
page_clicked
is a private method but it calls for a public method of another module.
Here is a Jasmine spec:
it('should bind events to pages', function() {
spyOn( search, 'get_results' );
$('.page:eq(0)').trigger('click');
expect( search.get_results ).toHaveBeenCalled();
});
This test works. Now I'm trying to write the same test for QUnit and can't find anything similar to spyOn. How to write this test for QUnit?
Share Improve this question edited Jan 15, 2012 at 13:02 Andreas Köberle 111k58 gold badges280 silver badges307 bronze badges asked Jan 15, 2012 at 12:48 Daniel J FDaniel J F 1,0642 gold badges16 silver badges31 bronze badges1 Answer
Reset to default 9Its cause QUnit doesn't have spies or mocks. But you can use the Sinon.JS mocking framework. Your test should look like this using sinon spy:
var spy = sinon.spy(search, 'get_results');
sinon.assert.calledOnce(spy);
本文标签: javascriptIs there a spyOn analogue in QUnitStack Overflow
版权声明:本文标题:javascript - Is there a spyOn analogue in QUnit? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741849648a2400988.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论