Last active
August 9, 2017 08:36
-
-
Save dcastro/3cbd458020a6c04f01fa9c7b54d3609b to your computer and use it in GitHub Desktop.
AngularJS - test doubles, cheat sheet
This file contains 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
// 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