1
我在jasmine
一個新手,試圖測試了jQuery click
回調函數測試jQuery的點擊回撥
$('#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)