Skip to content

Instantly share code, notes, and snippets.

@DanielGallo
Created April 10, 2018 22:48
Show Gist options
  • Save DanielGallo/1957b9d80f8338ef74f5bd587fde7c55 to your computer and use it in GitHub Desktop.
Save DanielGallo/1957b9d80f8338ef74f5bd587fde7c55 to your computer and use it in GitHub Desktop.
Jasmine - Throwing errors
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