Skip to content

Instantly share code, notes, and snippets.

@dcastro
Last active August 9, 2017 08:36
Show Gist options
  • Save dcastro/3cbd458020a6c04f01fa9c7b54d3609b to your computer and use it in GitHub Desktop.
Save dcastro/3cbd458020a6c04f01fa9c7b54d3609b to your computer and use it in GitHub Desktop.
AngularJS - test doubles, cheat sheet
// Testing a service with no dependencies
it('description', inject(function(myService) {
expect(myService).to.work.dammit;
}));
// Setting up some test doubles (`dependency` and `dependency2`)
it('description2', function() {
module({
dependency: {
property: 'hello',
func: function() { return 'world'; }
},
dependency2: {
property: 'hello',
func: function() { return 'world'; }
}
});
inject(function(myService) {
expect(myService).to.work.dammit;
});
});
// Setting up a test double (`dependency`) which depends on other services (e.g. `$q`)
it('description3', function() {
module(function($provide) {
$provide.factory('dependency', function($q) {
return {
asyncFuncX: $q.resolve,
asyncFuncY: $q.reject
};
});
});
inject(function(myService) {
expect(myService).to.work.dammit;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment