Skip to content

Instantly share code, notes, and snippets.

@mohuk
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohuk/fac9e35237b283813474 to your computer and use it in GitHub Desktop.
Save mohuk/fac9e35237b283813474 to your computer and use it in GitHub Desktop.
userProfileControllerTest
'use strict';
ddescribe('Controller: userProfile', function(){
beforeEach(module('SAPortal'));
beforeEach(module('app.dashboard'));
beforeEach(module('SAPortal.mocks'));
beforeEach(inject(init));
var _dataservice, _q, _userProfileData, _rootScope, _userProfile, _userProfileDeferred;
function init($injector, $controller){
_userProfileData = $injector.get('userProfileData');
_rootScope = $injector.get('$rootScope').$new();
_q = $injector.get('$q');
_dataservice = jasmine.createSpyObj('_dataservice', ['getUserProfile', 'getUserPermissions']);
_dataservice.getUserProfile.and.callFake(userProfilePromise);
function userProfilePromise(){
_userProfileDeferred = _q.defer();
return _userProfileDeferred.promise;
}
_userProfile = $controller('userProfile', {
dataservice: _dataservice
});
}
it('should set user profile on controller', setUserProfile);
function setUserProfile(){
_userProfileDeferred.resolve(_userProfileData.userProfile);
_rootScope.$digest();
expect(_userProfile.name).toBe("Johnny Joker");
expect(_userProfile.age).toBe(27);
expect(_userProfile.email).toBe("johnnyjoker@pokerface.com");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment