I am writing an app with AngularJS 1.5. I have some code in my service that I want to test. My service has a promise in it. I tried to write a unit test for it but it doesn't work. I am using Karma and Jasmine.
https://codepen.io/aubz/pen/VoWgbR
Here is my code snippet:
self.verifyCode = function(pin) {
var savedPin = localStorage.getItem("PIN");
if (savedPin == null) {
return $q.reject("NO_PIN_SET");
}
if (pin !== savedHashedPin) {
return $q.reject("INCORRECT_PIN");
}
return $q.when(true);
};
xit('should throw an error because there is no stored pin code', function () {
var pin = '1234';
Service
.verifyCode(pin)
.then(function (result) {
expect(result).toBe(null);
})
.catch(function (error) {
expect(error).not.toBe(null);
expect(error).toBe('NO_PIN_SET');
});
});
.then
block should be skipped, not expect the result to benull
. – georgeawg Aug 1 '19 at 17:22