javascript - How can I write a test which expects an 'Error' to be thrown in Jasmine?

Опубликовано: 05 Апрель 2024
на канале: Code Samples
64
0

I'm trying to write a test for the Jasmine Test Framework which expects an error. At the moment I'm using a Jasmine Node.js integration from GitHub.
In my Node.js module I have the following code:
throw new Error("Parsing is not possible");

Now I try to write a test which expects this error:
describe('my suite...', function() {
[..]
it('should not parse foo', function() {
[..]
expect(parser.parse(raw)).toThrow(new Error("Parsing is not possible"));
});
});

I tried also Error() and some other variants and just can't figure out how to make it work.


Смотрите видео javascript - How can I write a test which expects an 'Error' to be thrown in Jasmine? онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Code Samples 05 Апрель 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 64 раз и оно понравилось 0 людям.