I have a service in my angular app that looks something like this:
angular.module('BracketService', []).factory('BracketService', [function() { function compareByWeight(a, b) { return a.weight - b.weight; } function filterWeightGroup(competitors, lowWeight, highWeight) { //filter stuff } function createBracketsByWeightGroup(weightGroup) { //create some brackets } //set some base line values var SUPER_HEAVY_WEIGHT = 500; var SUPER_LIGHT_WEIGHT = 20; return { //create brackets from a list of competitors returnBrackets: function(competitors) { var brackets = {}; //get super light weights brackets.superLightWeights = createBracketsByWeightGroup( filterWeightGroup(competitors, 0, SUPER_LIGHT_WEIGHT) .sort(compareByWeight) ); brackets.superHeavyWeights = createBracketsByWeightGroup( filterWeightGroup(competitors, SUPER_HEAVY_WEIGHT, Infinity) .sort(compareByWeight) ); brackets.middleWeights = createBracketsByWeightGroup( filterWeightGroup(competitors, SUPER_LIGHT_WEIGHT, SUPER_HEAVY_WEIGHT) .sort(compareByWeight) ); return brackets; } }; }]); I would like to unit test not just the functions / properties that are exposed in the return statement, but also the functions that are outside of the return statement.
My test is currently set up something like this:
describe('BracketService', function() { beforeEach(module('bracketManager')); it('calling return brackets with no competitors will return 3 empty weight classes', inject(function(BracketService) { var mockCompetitors = []; var mockBracketResult = {superHeavyWeights: [[]], superLightWeights: [[]], middleWeights: [[]]}; expect(BracketService.returnBrackets(mockCompetitors)).toEqual(mockBracketResult); })); }); But how do I test the compare, filter and createBrackets functions that are not exposed by the return statement?
Thanks!