Sto provando a scrivere un test unitario che asserisce che la variabile corretta viene inviata alla proprietà resolve
di ui.bootstrap.modal
dai componenti Bootstrap di Angular-UI . Ecco quello che ho finora:Come testare la proprietà 'resolve' su un componente modale Bootstrap con interfaccia angolare
// 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; }
}
});
};
});
Vale la pena notare che la proprietà resolve.name
deve essere una funzione per la componente angolare-UI per funzionare correttamente - in precedenza avevo provato resolve: { name: name }
, ma questo non ha funzionato.
// 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)
}
});
});
}));
});
Al momento, questo è solo controllando che la proprietà resolve.name
è una funzione, ma quello che mi piacerebbe davvero fare è affermare la funzione resolve.name
ritorna Barney Rubble
. Questa sintassi, ovviamente, non funziona:
expect(modal.open).toHaveBeenCalledWith({
templateUrl: 'partials/editWorkflowModal.html',
controller: 'WorkflowEditCtrl',
scope: scope,
resolve: {
name: function() { return 'Barney Rubble'; }
}
});
Sembra che in qualche modo voglio spiare la funzione di controllare resolve.name
è stato chiamato con Barney Rubble
ma non riesco a trovare un modo per farlo. Qualche idea?
forse si potrebbe vedere questo: http://stackoverflow.com/questions/26853603/unit-testing-angular-bootstrap-modal/26942188 –