Last active
December 28, 2015 15:29
-
-
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."
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
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