79413492

Date: 2025-02-05 02:12:39
Score: 1
Natty:
Report link

I managed to fix it, I just invoked the original functions inside the test, then mocked genSalt and hash with the results.

const genSaltOriginal = (await vi.importActual<any>("bcryptjs")).genSalt;
const hashOriginal = (await vi.importActual<any>("bcryptjs")).hash;

const salt = await genSaltOriginal(10);
const hashedPassword = await hashOriginal(password, salt);

(genSalt as Mock).mockResolvedValueOnce(salt);
(hash as Mock).mockResolvedValueOnce(hashedPassword);
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: funnyVariable