Last active
March 9, 2016 17:57
-
-
Save peterheard01/140b9b979d8a05842724 to your computer and use it in GitHub Desktop.
this is a spy test double in javascript
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
//original Code | |
function HttpAuthenticator($http){ | |
this.load = (){ | |
return $http.get('/api/login') | |
}; | |
} | |
var Authenticator = new HttpAuthenticator(); | |
//the controller which will attempt to log in when it is loaded | |
angular.module('app').controller(function(Authenticator){ | |
Authenticator.load().then(function(dto){ | |
if(dto.authenticationSuccessful){ | |
$scope.showLoggedInPanel = true;//we want to test this value is set | |
} | |
}) | |
}); | |
//Stub Test Double - returns something | |
function AuthenticatorSuccessStub(){ | |
this.load = function(){ | |
return $.when({authenticationSuccessful:true;}); | |
}; | |
} | |
//Spy Test Double - sets something | |
function AuthenticatorSpy(){ | |
var loadedCalled = false; | |
this.load = function(){ | |
loadedCalled = true; | |
return $.when({}); | |
}; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment