【发布时间】:2014-04-08 14:17:00
【问题描述】:
我是jasmine的新手,正在尝试测试jquery click的回调函数
$('#upload-btn').click(function(){
$("#myModal").modal('show');
});
我的测试代码是
describe('upload button attaches to modal', function(){
it('attaches successfully', inject(function($controller, $httpBackend) {
spyOn($.fn, "click");
spyOn($.fn, "modal");
$httpBackend.expectGET('service/search/populate/procedureNumberList');
var scope = {}, ctrl = $controller('uploadARController', {
$scope : scope
});
$httpBackend.flush();
expect($('#upload-btn').click).toHaveBeenCalledWith(jasmine.any(Function));
$('#upload-btn').click();
expect($.fn.modal).toHaveBeenCalled() <<<---- Failing here;
}));
})
但是当我执行测试时得到以下结果
PhantomJS 1.9.7 (Windows 7) Upload AR Test upload button attaches to modal attaches successfully FAILED
Expected spy modal to have been called.
PhantomJS 1.9.7 (Windows 7): Executed 3 of 3 (1 FAILED) (0.165 secs / 0.026 secs)
【问题讨论】:
标签: javascript angularjs unit-testing testing jasmine