#don't understand why my Jasmine test is a failure

9 messages · Page 1 of 1 (latest)

pearl snow
#

Hi, I've just finished the Introduction to Unit Testing course and I'm training doing tests for the candies challenge .
I'm trying to test the errors as there are Guaranteed constraints (1 ≤ n ≤ 10).
My code send me the error, but the test is failing and I don't understand why. Could you help me? I guess I don't see clearly anymore 🙈

I don't find the answer on Google links or stackoverflow...
I tried with and without error message, with and without try / catch block 🤔
I also tried to change the assert like this : expect(result).toThrow(new Error("sorry... n must be >= 1")); but it doesn't change.
I'm coding on GitHub codespace, I don't know if this could be the reason?

Here are some screenshots
Thanks a lot !

GitHub

Contribute to Dylan-Israel/100AlgorithmsChallenge development by creating an account on GitHub.

cunning vale
sudden socket
#

@pearl snow the error is very straight forward.
Look at the values in your test and you can see that n is defined as 0 and in your candies function this will thro an error as n cannot be less than 1

pearl snow
sudden socket
#

you need to provide a function to expect which invokes your function:

expect(() => candies(0, 5)).toThrowError('...')
#

otherwise, the function will run, and the error will be thrown outside of expect

#

the error will not be saved as the result

#

there is ways around this but that is just messy

pearl snow
#

Sorry, I wasn't available and didn't see your answer. Thank you so much, now I understand 🤩. Light is on 💡