Skip to content

Instantly share code, notes, and snippets.

@jonnybojangles
Last active December 28, 2015 11:19
Show Gist options
  • Save jonnybojangles/7492609 to your computer and use it in GitHub Desktop.
Save jonnybojangles/7492609 to your computer and use it in GitHub Desktop.
Test private provider methods in AngularJS with Jasmine. How would you test setDay? Thanks: http://www.yearofmoo.com/2013/09/advanced-testing-and-debugging-in-angularjs.html
angular.module('widget.providers', []).
provider('day', function(){
var day = '';
return {
setDay: function(current){
day = current;
},
$get: function(){
return {
day: day + 'day'
}
}
}
});
describe('widget.providers', function(){
beforeEach(function () {
module('widget.providers');
});
describe("Day provider", function () {
"use strict";
it('Testing providers day method default', inject(function(day){
expect(day.day).toBe('day');
}));
});
describe("Day provider: setDay", function () {
"use strict";
beforeEach(function () {
module(function(dayProvider){
"use strict";
dayProvider.setDay('Bilbo');
});
});
it('Testing providers setDay method', inject(function(day){
expect(day.day).toBe('Bilboday');
}));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment