Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
describe('SignupController', function() {
beforeEach(module('manotes.controllers'));
var $scope, $controller, $rootScope, $httpBackend, Account;
beforeEach(inject(function(_$controller_, _$rootScope_, _$httpBackend_){
$httpBackend = _$httpBackend_;
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
Account = jasmine.createSpy('Account');
$controller = _$controller_('SignupController', {
$scope: $scope,
Account: Account,
});
}));
describe('$scope.user', function() {
it('The default value of user email should be null', function() {
expect($scope.user.email).toBeNull();
});
it('The default value of user username should be null', function() {
expect($scope.user.username).toBeNull();
});
it('The default value of user password should be null', function() {
expect($scope.user.password).toBeNull();
});
it('The default value of loading should be false', function() {
expect($scope.loading).toBeFalsy();
});
});
describe('and When I sign up', function() {
it('change loading to true', function() {
$scope.signup();
expect($scope.loading).toBeTruthy();
});
it('should call Account to save', function() {
$scope.signup();
expect(Account.save).toHaveBeenCalled();
});
it('should call Account to save with $scope.user', function() {
$scope.signup();
expect(Account.save).toHaveBeenCalledWith(
$scope.user,
$controller.signupHandleSuccess,
$controller.signupHandleError
);
});
});
describe('signupHandleSucess', function() {
it('should set loading to false', function() {
Account.save = function(user, okCall, errorCall) {
if (user == 'OK') {
okCall()
}
if (user == 'ERROR') {
errorCall()
}
};
$scope.loading = true;
// $controller.signupHandleSuccess();
// expect($scope.loading).toBeFalsy();
$scope.user = 'ERROR';
$scope.signup();
expect($scope.loading).toBeFalsy();
});
});
describe('signupHandleError', function() {
it('should set loading to false', function() {
$scope.loading = true;
$controller.signupHandleSuccess();
expect($scope.loading).toBeFalsy();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.