You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
describe('MultiRecipeLoader',function(){varmockBackend,recipe,loader;// The _$httpBackend_ is the same as $httpBackend. Only written this way to// differentiate between injected variables and local variablesbeforeEach(inject(function(_$httpBackend_,Recipe,MultiRecipeLoader){recipe=Recipe;mockBackend=_$httpBackend_;loader=MultiRecipeLoader;}));it('should load list of recipes',function(){mockBackend.expectGET('/recipes').respond([{id: 1},{id: 2}]);varrecipes;varpromise=loader();promise.then(function(rec){recipes=rec;});expect(recipes).toBeUndefined();mockBackend.flush();expect(recipes).toEqualData([{id: 1},{id: 2}]);});});
first I'd suggest the usage of leading and trailing underscores for all injected variables. the book is not explaining these are ignored by the injector and using this notation helps to highlight injected variables.
second, I'd like to point out that the spec will fail as "loader" is the actually promise object and not a function.
my suggestion would be: (this is wrapped in a services test suite where the Recipe resource and $httpBackend mock are scoped for all individual service test suites)
varRecipe,$httpBackend;describe('MultiRecipeLoader',function(){varMultiRecipeLoader;//injector will ignore front and trailing underscore, this notation is to clarify injected variables//yet give the ability to write tests using variables exactly the same way the actual implementations dobeforeEach(inject(function(_$httpBackend_,_Recipe_,_MultiRecipeLoader_){Recipe=_Recipe_;$httpBackend=_$httpBackend_;MultiRecipeLoader=_MultiRecipeLoader_;}));it('should load a list of recipes',function(){$httpBackend.expectGET('/recipes').respond([{id:1},{id:2}]);varrecipes;varpromise=MultiRecipeLoader;promise.then(function(rec){recipes=rec;});expect(recipes).toBeUndefined();$httpBackend.flush();expect(recipes).toEqualData([{id:1},{id:2}]);});
The text was updated successfully, but these errors were encountered:
current github code:
my suggestion would be: (this is wrapped in a services test suite where the Recipe resource and $httpBackend mock are scoped for all individual service test suites)
The text was updated successfully, but these errors were encountered: