lundi 22 mars 2021

Returning a Promise from "describe" is not supported In Nestjs Unit testing

** I want to do unit testing of service in nestjs using mongoose ** This error comes up at the end Returning a Promise from "describe" is not supported. Tests must be defined synchronously. Returning a value from "describe" will fail the test in a future version of Jest.

enter image description here

`

import { Test, TestingModule } from '@nestjs/testing';
import { MongooseModule } from '@nestjs/mongoose';

import { closeInMongodConnection, rootMongooseTestModule } from '../test-utils/mongo/MongooseTestModule';
import { UserSchema } from './user.model';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';

describe('UserController', async () => {
  let controller: UsersController;
  let service: UsersService;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      imports: [rootMongooseTestModule(), MongooseModule.forFeature([{ name: 'User', schema: UserSchema }])],
      controllers: [UsersController],
      providers: [UsersService],
    }).compile();

    controller = module.get<UsersController>(UsersController);
    service = module.get<UsersService>(UsersService);
  });

  it('should be defined', () => {
    expect(controller).toBeDefined();
  });

  it('should return all the events', async () => {
    const result = {
      totalDocs: 0,
      resource: [],
    };

    const data = await service.findAll();
    expect(data).toEqual(result);
  });
  

  afterAll(async () => {
    await closeInMongodConnection();
  });
});
`

strong text`]2

Aucun commentaire:

Enregistrer un commentaire