Created
April 10, 2018 22:48
-
-
Save DanielGallo/1957b9d80f8338ef74f5bd587fde7c55 to your computer and use it in GitHub Desktop.
Jasmine - Throwing errors
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
describe('Throwing errors', function() { | |
var user = { | |
getUser: function(id) { | |
// Do something | |
} | |
}; | |
it('Should throw a custom error message', function() { | |
spyOn(user, 'getUser').and.throwError('No user ID specified'); | |
expect(user.getUser).toThrowError('No user ID specified'); | |
}); | |
it('Should throw a custom error message - example 2', function() { | |
spyOn(user, 'getUser').and.throwError('Invalid user ID'); | |
expect(function() { user.getUser('test') }).toThrowError('Invalid user ID'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment