I have defined a method for my controller, like
$scope.submitForm = ( username, password ) =>{
$http({
method: 'post',
url: 'balabala',
params: {username, password}
}).success( res => { /* */ } );
}
My test specs look like:
descript('myController', () => {
beforeEach(module('myModule'));
let controller, httpBackend, http, scope;
beforeEach(inject(($controller, $httpBackend, $http, $scope) => {
scope = $scope.$new();
httpBackend = $httpBackend;
http = $http;
controller = $controller;
httpBackend.when('POST', '/login')
.respon({
result: 'ok'
});
}));
it('should POST login', () => {
httpBackend.expectPOST('/login');
const myController = controller('myController', {
$scope: scope,
$http: http
});
scope.submitForm();
httpBackend.flush();
});
});
How can I make sure that username
and password
have been posted?
Aucun commentaire:
Enregistrer un commentaire