I am confused about the way AngularJS $resource service is supposed to be mokced for testing. I found two ways to use $httpBackend service for it. One way (taken from a Pluralsight tutorial):
describe('test', function() {
beforeEach(module('name'));
it('text', inject(function($httpBackend) {
$httpBackend.expectGET("/url");
// some code
$httpBackend.flush();
});
}
An other way (copied from this SO answer):
describe('test', function () {
var $httpBackend;
beforeEach(angular.mock.module('name'));
beforeEach(function () {
angular.mock.inject(function ($injector) {
$httpBackend = $injector.get('$httpBackend');
})
});
describe('text', function () {
it('text', inject(function (User) {
$httpBackend.expectGET('/url')
.respond([{
property: 'test'
}]);
// Some code
$httpBackend.flush();
}));
});
});
I don't understand why the first way, uses module directly whereas the second way does angular.mock.module. And then the httpBackend service is injected so differently. The second way is so much more verbose. If the first way works, what's the point in all that verbosity of the second way?