I have a string that is used to display text. It is initially set to null, then is updated throughout a function with status updates. I want to make sure the string is set to the correct status updates throughout the function's lifetime.
Jasmine's spies seem focused on testing functions and their interactions. I specifically want to test a string's history. Assuming the following code:
(function() {
$this.loggingIn = false;
$this.submit = function () {
$this.loggingIn = "Requesting access...";
$this.errorMessage = "";
var aThing = {};
var aSecondaryThing = {};
$http.post(aThing)
.success(function (data, status, headers, config) {
$this.loggingIn = "Validating credentials...";
$http.post(aSecondaryThing)
.success(function (data, status, headers, config) {
$this.loggingIn = "Done!";
})
.error(function (data, status, headers, config) {
$this.errorMessage = data.error_description || "Invalid username or password.";
$this.loggingIn = false;
});
})
.error(function (data, status, headers, config) {
$this.errorMessage = data.error_description || "Invalid username or password.";
$this.loggingIn = false;
});
return false;
};
})();
This function is abridged from our original Angular code. Nothing's missing aside from the wiring to make the controller work and the post actions.
Is there a way to test that loggingIn
is set to "Validating credentials..."
and then "Done!"
without writing a setter function to handle it?