I have next Card model
export class Card extends Document {
@Prop({ required: true, immutable: true})
id: string;
@Prop({ required: true })
name: string;
...
export const CardSchema = SchemaFactory.createForClass(Card);
}
And test are freezing when i try to mock data in test by
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { AppModule } from '../../../../src/app.module';
import { createAuthToken } from '../../../helpers/auth.helper';
import { Card } from '../../../../src/card/card.schema';
import { Model } from 'mongoose';
import { getModelToken } from '@nestjs/mongoose';
import mockingoose from 'mockingoose';
describe('GET /card:id', () => {
let app: INestApplication;
let cardModel: Model<Card>;
beforeAll(async () => {
...
});
it('Should receive card data', async () => {
...
mockingoose(cardModel).toReturn(_doc, 'findOne');
return request(app.getHttpServer())
.get('/card/test')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${createAuthToken(user)}`)
.expect(200);
})
...
});
i have controller, DTO and service for load entity.
here is console screen: test log screen