jeudi 9 juillet 2015

How do I test a string's values in Jasmine?

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:

$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;
};

Is there a way to test that loggingIn is set to "Validating credentials..." and then "Done!" without writing a setter function to handle it?

Aucun commentaire:

Enregistrer un commentaire