jeudi 14 février 2019

jest toEqual not working with exception matching

I'm new to jest so I'm not sure if its my fault. So here is my test case

    it('should throw error if wrong email or phone number is provided', async () => {
      await expect(userService.verifyCredentials('invalidemail@invaliddomain.com', 'sayantan94'))
        .rejects
        .toEqual(new UnauthorizedException('Invalid email or phone number'));
    })

But this fails even though the same exception is thrown. Here is the output

FAIL  src/modules/user/user.service.spec.ts (5.156s)
● UserService › verifyCredentials › should throw error if wrong email or phone number is provided

expect(received).toStrictEqual(expected)

Expected value to equal:
  [Error: [object Object]]
Received:
  [Error: [object Object]]

Difference:

Compared values have no visual difference.

  88 |       await expect(userService.verifyCredentials('invalidemail@invaliddomain.com', 'sayantan94'))
  89 |         .rejects
> 90 |         .toStrictEqual(new UnauthorizedException('Invalid email or phone number'));
     |          ^
  91 |     })
  92 |   })
  93 |

How do I check this?

Aucun commentaire:

Enregistrer un commentaire