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 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`);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With