Angular-UI Bootstrap 구성 요소의 속성 인 resolve
속성으로 올바른 변수를 보내고 있다고 주장하는 단위 테스트를 작성하려고합니다. . 여기에 지금까지 무엇을 가지고 :각도 UI 부트 스트랩 모달 구성 요소에서 'resolve'속성을 단위 테스트하는 방법
// Controller
angular.module('app')
.controller('WorkflowListCtrl', function ($scope, $modal) {
// Setup the edit callback to open a modal
$scope.edit = function(name) {
var modalInstance = $modal.open({
templateUrl: 'partials/editWorkflowModal.html',
controller: 'WorkflowEditCtrl',
scope: $scope,
resolve: {
name: function() { return name; }
}
});
};
});
그것은 resolve.name
속성은 각도-UI 구성 요소가 제대로 작동 할 수있는 기능이 있어야한다는 지적 가치 - 이전에 나는 resolve: { name: name }
을 시도했다하지만이 작동하지 않았다. 순간
// Unit Test
describe('Controller: WorkflowListCtrl', function() {
// load the controller's module
beforeEach(module('app'));
var workflowListCtrl,
scope,
modal;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
modal = {
open: jasmine.createSpy()
};
workflowListCtrl = $controller('WorkflowListCtrl', {
$scope: scope,
$modal: modal
});
it('should allow a workflow to be edited', function() {
// Edit workflow happens in a modal.
scope.edit('Barney Rubble');
expect(modal.open).toHaveBeenCalledWith({
templateUrl: 'partials/editWorkflowModal.html',
controller: 'WorkflowEditCtrl',
scope: scope,
resolve: {
name: jasmine.any(Function)
}
});
});
}));
});
이 단지
resolve.name
속성은 함수임을 확인하지만, 내가 정말하고 싶은 것은
resolve.name
기능이
Barney Rubble
을 반환 주장이다. 이 구문은 분명히 작동하지 않습니다 어떻게 든이
Barney Rubble
호출했지만, 난 그렇게 할 수있는 방법을 알아낼 수 없습니다 확인하기 위해
resolve.name
기능을 감시 할 같은
expect(modal.open).toHaveBeenCalledWith({
templateUrl: 'partials/editWorkflowModal.html',
controller: 'WorkflowEditCtrl',
scope: scope,
resolve: {
name: function() { return 'Barney Rubble'; }
}
});
것 같다. 어떤 아이디어?
어쩌면 당신이 볼 수 : http://stackoverflow.com/questions/26853603/unit-testing-angular-bootstrap-modal/26942188 –