Skip to content

Instantly share code, notes, and snippets.

@sonicparke
Last active December 30, 2015 16:25
Show Gist options
  • Save sonicparke/2da975fec86438eef95f to your computer and use it in GitHub Desktop.
Save sonicparke/2da975fec86438eef95f to your computer and use it in GitHub Desktop.
testing functions
(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);
}
}
})();
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