Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonnybojangles/7522052 to your computer and use it in GitHub Desktop.
Save jonnybojangles/7522052 to your computer and use it in GitHub Desktop.
Testing a provider with a private method. See the use of provide injector "withPrivateProvider."
angular.module('widget', []).
provider('withPrivate', [function(){
var query = 'First';
this.demo = 'Third';
this.setQuery = function(newQuery){
query = newQuery;
};
this.$get = [function(){
return {
getQuery: function(){
return query;
}
};
}];
}]);
describe('Widget: withPrivate', function(){
"use strict";
var p;
beforeEach(module('widget', function(withPrivateProvider){
p = withPrivateProvider;
}));
it('Var query, default value', inject(function(withPrivate){
// Default value
expect(withPrivate.getQuery()).toBe('First');
}));
it('Member demo, private', inject(function(withPrivate){
expect(p.demo).toBe('Third');
}));
it('Method setQuery, private', inject(function(withPrivate){
var val = 'Second';
p.setQuery(val);
expect(withPrivate.getQuery()).toBe(val);
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment