Created
August 12, 2021 23:50
-
-
Save jpmoura/720171a4e5ded4bd8bc6ba69271d0b34 to your computer and use it in GitHub Desktop.
Mocking bcrypt library with Jest and TypeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using compare method as example | |
const bcryptCompare = jest.fn().mockRejectedValue(new Error('Random error')); | |
(bcrypt.compare as jest.Mock) = bcryptCompare; | |
//call method that uses bcrypt.compare with async | |
const bcryptCompare = jest.fn().mockResolvedValue(true); | |
(bcrypt.compare as jest.Mock) = bcryptCompare; | |
//call method that uses bcrypt.compare with async |
You're welcome
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!