#Testing Authentication Service in NestJS 10 with Jest and bcrypt
21 messages · Page 1 of 1 (latest)
Why not jest.spyOn(crypt, 'compare').mockResolvedValue(true)
I tried it , but i face same problem ... do not know what wrong....
Package versioins?
Some packages incoherence!? 🤔
The packages look fine, I think. I don't see anything immediate that would give me concern
Maybe I haven't implemented the process very well , in other to bypass bcrypt compare method in test of user sign in. 🤔
?
Your setup generally looks fine. Can you provide a minimum reproduction repository so I can tinker with it locally?
ok, i will send you git repo
https://github.com/Ulrich15/Wanago.io-Tuto.git
That's is the github repository of the projet, i tried to test authentication controller
Thanks 🙏
import * as bcrypt from 'bcrypt' has the compare (and other methods) as Getters that point to bcrypt.default.compare. An easy fix is to change the import inside the test to import bcrypt from 'bcrypt'
diff --git a/src/authentication/authentication.service.spec.ts b/src/authentication/authentication.service.spec.ts
index fede224..b770858 100644
--- a/src/authentication/authentication.service.spec.ts
+++ b/src/authentication/authentication.service.spec.ts
@@ -8,7 +8,7 @@ import { getRepositoryToken } from '@nestjs/typeorm';
import { User } from '../user/entities/user.entity';
import mockJwtService from '../utils/mocks/jwt.service';
import mockConfigService from '../utils/mocks/config.service';
-import * as bcrypt from 'bcrypt';
+import bcrypt from 'bcrypt';
import mockUser from '../utils/mocks/user.mock';
jest.mock('bcrypt', () => ({
i think there is a problem with latest version of my plugins, i clone this repo https://github.com/mwanago/nestjs-typescript.git, using nestjs 7 and it passes well with this test
Without a direct reproduction of what you're doing, I won't be able to say. The diff I gave above works
I have and authenticaton service using bcrypt compare method to login user, i want to make integration test of this service, but when i use the code as the one present in this repository https://github.com/mwanago/nestjs-typescript.git; in my recent project, i faced this issues (in image).
I don't really know if there is an update in bcrypt library or in Jest librairy for nestjs 10
Is that your current repo, or just a repo you've cloned and are using?