Skip to content

Instantly share code, notes, and snippets.

@trumbitta
Created January 30, 2015 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trumbitta/406975602bb018ecdbcd to your computer and use it in GitHub Desktop.
Save trumbitta/406975602bb018ecdbcd to your computer and use it in GitHub Desktop.
Angular testing with constant
angular.module('wiz.config', [])
.constant('ENV', {URL:{FULL:'http://localhost:1337'}})
;
angular.module('wiz.factories.yeah', ['ngResource'])
.factory('yeahFactory', function ($resource, ENV) {
'use strict';
return $resource([
ENV.URL.FULL,
'/yeah'
].join(''), {},
{
'get': {
method:'GET',
interceptor: {
responseError: function(error) {
console.log('error • get yeah:', error);
}
}
},
}
);
});
describe('Service: wiz.factories.yeah', function() {
'use strict';
var yeahFactory,
mockYeahData,
$httpBackend,
yeahRequestHandler;
beforeEach(function() {
module('wiz.factories.yeah');
});
beforeEach(inject(function(_yeahFactory_, _$httpBackend_) {
yeahFactory = _yeahFactory_;
$httpBackend = _$httpBackend_;
yeahData =
{
'success': true,
'data': {
'oh': 'yeah'
}
};
yeahRequestHandler = $httpBackend.when('GET', '/yeah')
.respond(mockYeahData);
}));
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
it('should GET a yeah', function() {
yeahFactory.get().$promise
.then(function(data) {
expect(data).toEqual(mockYeahData);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment