Ticket: Handling Errors - Test passes, but did not got the ticket - Explanation

For a newcomer in the developer’s world, this is an quite difficult test. The main difficulty here is to understand what is an Unit Test and why not to use expect in your code.

In case you did not know (like me), when you reach at this point, when you use

npm test -t 'error-handling.test.js'

you are calling JEST, a JavaScript Testing Framework. So every time you see a code like this:

    test('the flavor list contains lime', () => {
      expect(getAllFlavors()).toContain('lime');
    });

you telling to JEST: please take a look at expected results for me.

So when you put a code like this in your project:

expect(e).not.toBeUndefined()
expect(e.toString()).toContain("Error: <some text here>")

you are creating an “false positive” because you are creating a new unit test that validates what you expect, but you are not really handling the issue.

For furthermore explanations, please see this topic: Ticket XYZ fails but I'm sure my implementation is correct!

Congrats to the MongoDB University Team! This course is a top notch course. Really appreciated!

1 Like