Last active
December 28, 2015 11:19
-
-
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
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.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