I'm working in the fontend side, and testing my library, I receive an error that I expect but I cannot make an assertion. I have the next code:
it('If the username is not entered, I get an error', () => {
try {
new SDK('test', {
password: 'aaaabbbbcccc',
key: 'ddddeeefff',
});
} catch (error) {
expect(error).toThrow(
`Error: The 'username' property has not been entered`
);
}
});
As you can see, for the authentication of my library, I need: username, password and key. This is the error that I get:
Thank you!
I'm working in the fontend side, and testing my library, I receive an error that I expect but I cannot make an assertion. I have the next code:
it('If the username is not entered, I get an error', () => {
try {
new SDK('test', {
password: 'aaaabbbbcccc',
key: 'ddddeeefff',
});
} catch (error) {
expect(error).toThrow(
`Error: The 'username' property has not been entered`
);
}
});
As you can see, for the authentication of my library, I need: username, password and key. This is the error that I get:
Thank you!
Share Improve this question edited May 22, 2020 at 8:49 jonrsharpe 122k30 gold badges267 silver badges474 bronze badges asked May 22, 2020 at 2:17 LuisLuis 2,1437 gold badges33 silver badges53 bronze badges1 Answer
Reset to default 13I found my problem. It was necessary for the "expect" to catch the exception and then use the appropriate matcher (without try/catch block)
it('If the username is not entered, I get an error', () => {
expect(() => {
new SDK('test', {
password: 'aaaabbbbcccc',
key: 'ddddeeefff',
});
}).toThrowError(`The 'username' property has not been entered`);
});