我如何使用Jasmine
在Angular中测试以下服务angular.module('xyz')
.service('noteCardDisplay', function () {
function waitForDialog() {
var dialogWrapper, dialogModal;
dialogWrapper = angular.element('.modal-content').parent().parent();
dialogWrapper.css('height', 475);
dialogWrapper.css('width', 650);
dialogWrapper.css('margin-left', 300);
dialogWrapper.css('margin-top', 200);
dialogModal = angular.element('.modal-content').parent();
dialogModal.css('margin', 0);
}
return {
waitForDialog: waitForDialog
};
});
答案 0 :(得分:0)
似乎您的服务处理DOM元素,那么您应该使用$compile
来创建DOM片段以进行测试。然后,您可以使用angular.element.attr
验证属性的某些值。
这看起来像这样:
it('div should have title attribute', inject(function($rootScope, $compile) {
$rootScope.title = 'new title';
element = $compile('<div title="{{title}}"></div>')($rootScope);
$rootScope.$digest();
expect(element.attr('title')).not.toBe('');
expect(element.attr('title')).toBe(undefined);
}));