作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编写一个测试来测试我的应用程序的删除功能。我创建了一个模拟删除 $modal 来模拟取消/确认删除。
var modalInstanceMock=
{
result: {
then: function(confirmCallback, cancelCallback) {
//Store the callbacks for later when the user clicks on the OK or Cancel button of the dialog
this.confirmCallBack = confirmCallback;
this.cancelCallback = cancelCallback;
}
},
confirmCallBack: function(item){
return true;
},
cancelCallback: function(type){
return false;
},
close: function( item ) {
//The user clicked OK on the modal dialog, call the stored confirm callback with the selected item
this.result.confirmCallBack( item );
},
dismiss: function( type ) {
//The user clicked cancel on the modal dialog, call the stored cancel callback
this.result.cancelCallback( type );
}
};
我在每次测试之前都会这样做:
beforeEach(inject(function($modal) {
spyOn($modal, 'open').andReturn(modalInstanceMock);
}));
这非常有效:
var newRes = scope.deleteCar(car);
scope.modalInstance.close("ok");
但是当我尝试这个时:
var newRes = scope.deleteCar(car);
scope.modalInstance.dismiss("ok");
我收到一个 Type:error undefined is not a function at Object.modalInstanceMock.dismiss。
无法理解当关闭工作正常时出了什么问题。
最佳答案
在beforeEach中初始化,
modalInstance = {
close: jasmine.createSpy('modalInstance.close'),
dismiss: jasmine.createSpy('modalInstance.dismiss')
},
然后期待。
关于javascript - Angular JS 驳回 $modalInstance : undefined is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27226438/
我是一名优秀的程序员,十分优秀!