Last active
December 30, 2015 16:25
-
-
Save sonicparke/2da975fec86438eef95f to your computer and use it in GitHub Desktop.
testing functions
This file contains hidden or 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
(function() { | |
"use strict"; | |
angular.module('msa') | |
.controller('msaCtrl', msaCtrl); | |
msaCtrl.$inject = ['AppService', 'AppACL']; | |
function msaCtrl( AppService, AppACL ) { | |
var vm = this; | |
vm.getAllowableNetworks = getAllowableNetworks; | |
vm.logout = logout; | |
// How do I make this stuff testable? | |
// Option mappers | |
function getAllowableNetworks() { | |
return AppService.getNetworks(); | |
} | |
function logout() { | |
AppACL.logout(false, true); | |
} | |
} | |
})(); |
This file contains hidden or 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
describe('MSA', function() { | |
beforeEach(module('msa')); | |
beforeEach( | |
inject(function($controller) { | |
// Mock up the AppACL user function | |
as = { | |
getNetworks: function() { | |
return true; | |
} | |
} | |
// Mock up the AppACL user function | |
aacl = { | |
logout: function() { | |
loggedOut = true; | |
} | |
} | |
// Setup the creation of the controller to be used in controller tests | |
createController = function() { | |
return $controller('msaCtrl as msa', { | |
AppService: as, | |
AppACL: aacl | |
}); | |
} | |
// Create the Controller | |
msa = createController(); | |
}) | |
) | |
// this one works | |
it('should logout', function() { | |
msa.logout(); | |
expect(loggedOut).toBe(true); | |
}) | |
// this one doesn't | |
it('should get networks', function() { | |
spyOn(msa.AppService, 'getNetworks') | |
msa.getAllowableNetworks(); | |
expect(msa.AppService.getNetworks).toHaveBeenCalled(); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment