Questions tagged [nestjs-testing]
34 questions
0
votes
1 answer
How to test service in Nestjs?
service.ts
@Injectable()
export class FileUploadService {
private readonly logger = new Logger(FileUploadService.name);
constructor(private readonly httpService: HttpService) {}
}
spec.ts
beforeEach(async () => {
const app: TestingModule…
0
votes
0 answers
NestJS e2e tests cannot find module with absolute path
When I run e2e test in my application with the command:
jest --no-cache --config ./test/jest-e2e.json --detectOpenHandles
I receive some errors like:
Cannot find module 'src/modules/shared/shared.module' from…
0
votes
1 answer
Please make sure that the argument CrawlsRepositoryat index [0] is available in the RootTestModule context
I'm trying to test a class via Nest. In this class (cf image below), the person who coded the class, create a repository via typeorm.
service code
import { Injectable, BadRequestException } from '@nestjs/common';
import { CreateCrawlDto } from…

BrianLEE
- 1
- 2
0
votes
1 answer
how to provide injectables to service when Testing with NestJs Test.createTestingModule function?
I am trying to set up my test suite for a specific service which takes in a repository and two other services at the constructor parameter level injection using Nest's built-in Dependency Injection (DI).
The application is working fine no issue…

Louguiman
- 5
- 1
0
votes
1 answer
ConfigService is undefined while running testcases in Nest.js
I am running nestjs server locally and if I test with postman it works fine. But when I run testcases, the ConfigService gets undefined!
app.module.ts
@Module({
imports: [
ConfigModule.forRoot({ load: [configuration], isGlobal: true }),
…

Prashant Patel
- 21
- 3
0
votes
1 answer
Get provider injected with key in a NetJS Test
I have a provider which I inject using a key:
export const myProvider = {
provide: SOME_PROVIDER,
useFactory: () => {
return SomeWrappedInstance;
},
};
In my tests I want to access this provider which I inject with…

user17714968
- 25
- 5
0
votes
1 answer
Jest's .toHaveBeenCalledWith() assertion doesn't work with injected mock repo in NestJS TestingModule
I'm writing tests for my users.service file. To test the update method, I wanted to check if the user repository's persistAndFlush() method is called with the right data.
users.service.ts
import { InjectRepository } from '@mikro-orm/nestjs';
import…

Bundologus
- 3
- 3
0
votes
0 answers
Nestjs testing against real DB
I have TestingCoreModule which includes only the necessary modules for the e2e graphlq resolver tests and below is my DatabaseModule.
@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: async (configService: ConfigService) =>…

user2657198
- 139
- 1
- 8
0
votes
1 answer
NestJS - gRPC Client E2E Test
I am trying to write an e2e test for my NestJS microservice that has a gRPC client. No matter what I do to try and mock the ClientsModule in the e2e test it still seems to not pick up the config and is unable to locate the *.proto file.
Please find…

mh377
- 1,656
- 5
- 22
- 41
0
votes
1 answer
NestJS Kafka e2e test examples
Does anybody know how to write e2e tests for Kafka to test producing/consuming events ?.
I have had a look at the NestJS github repo below and cant find anything.
https://github.com/nestjs/nest/tree/master/sample

mh377
- 1,656
- 5
- 22
- 41
0
votes
2 answers
Nestjs Testing in signup BadRequestException: email in use error
user.service.ts
async findWithMail(email:string):Promise {
return this.userRepository.findOne({email});
}
auth.service.ts
async signup(email:string,password:string,name?:string,surname?:string,phone:string){
if(email) {
const…

MUSTAFA KENDİGÜZEL
- 73
- 7
0
votes
1 answer
NestJS throwing error Cannot find module 'jest-util'
I'm running a NestJS api with extensive code, everything is working fine, and it has almost full code coverage with all kinds of different mocks.
While trying to implement a test for the provider of a new module, I was prompted with this…

Rafael Eufrázio
- 11
- 5
0
votes
1 answer
Can't call useMocker on TestingModule
I'm trying to execute useMocker on the following piece of code:
const module = await Test.createTestingModule({
providers: [
RatingService,
UserService,
RentService,
{ provide:…

Rafael Eufrázio
- 11
- 5
0
votes
2 answers
How to change/edit a key in ConfigService - Nestjs
I have created a Nestjs server and loading configs using .env file
ConfigModule.forRoot({
isGlobal: true,
envFilePath: [`../.env.${process.env.NODE_ENV}`, '../.env'],
}),
I have e2e test cases and need to test a condition on different…

Midhun G S
- 906
- 9
- 22
0
votes
0 answers
Mocking Controller dependency in Nestjs
I am trying to mock my controller using nestjs createTestingModule and I have added overrider provider to mock the service but it still giving me this error
Screenshot:
I also tried added the other dependencies too but the error is same
Here is my…

Haris Jamil
- 1
- 1