-
-
Save robertdean/7682282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mocked Service | |
angular.module('mock.users', []). | |
factory('UserService', function($q) { | |
var userService = {}; | |
userService.get = function() { | |
return { | |
id: 8888, | |
name: "test user" | |
} | |
}; | |
// other stubbed methods | |
return userService; | |
}); | |
// Controller Unit Tests | |
describe('My Controller', function() { | |
var ctrl, scope; | |
beforeEach(module('module.containing.controller')); | |
// include previous module containing mocked service which will override actual service, because it's declared later | |
beforeEach(module('mock.users')); | |
beforeEach(inject(function($controller, $rootScope, _UserService_) { // inject mocked service | |
scope = $rootScope.$new(); | |
ctrl = $controller('MyController', { | |
$scope: scope, | |
UserService: _UserService_ | |
}); | |
})); | |
// unit tests go here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment