How to use the @nestjs/mongoose.getModelToken function in @nestjs/mongoose

To help you get started, we’ve selected a few @nestjs/mongoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmcdo29 / testing-nestjs / apps / mongo-sample / src / cat / cat.service.spec.ts View on Github external
beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [
        CatService,
        {
          provide: getModelToken('Cat'),
          // notice that only the functions we call from the model are mocked
          useValue: {
            new: jest.fn().mockResolvedValue(mockCat()),
            constructor: jest.fn().mockResolvedValue(mockCat()),
            find: jest.fn(),
            findOne: jest.fn(),
            update: jest.fn(),
            create: jest.fn(),
            remove: jest.fn(),
            exec: jest.fn(),
          },
        },
      ],
    }).compile();

    service = module.get(CatService);
github EricKit / nest-user-auth / test / app.e2e-spec.ts View on Github external
beforeEach(async () => {
    const moduleFixture: TestingModule = await Test.createTestingModule({
      imports: [AppModule],
      providers: [
        UsersService,
        {
          provide: getModelToken('User'),
          useValue: UserModel,
        },
      ],
    }).compile();

    app = moduleFixture.createNestApplication();
    await app.init();
  });
github jkchao / blog-service / src / module / links / __test__ / link.service.spec.ts View on Github external
beforeAll(async () => {
    const module = await Test.createTestingModule({
      imports: [LinksModule]
    })
      .overrideProvider(getModelToken('Links'))
      .useValue(mockRepository)
      .compile();

    linksService = module.get(LinksService);
  });
github jkchao / blog-service / src / module / tags / __test__ / tags.service.spec.ts View on Github external
beforeAll(async () => {
    const module = await Test.createTestingModule({
      imports: [TagsModule]
    })
      .overrideProvider(getModelToken('Tags'))
      .useValue(mockRepository)
      .overrideProvider(getModelToken('Articles'))
      .useValue({})
      .overrideProvider(ArticlesSercice)
      .useValue({
        aggregate() {
          return [
            {
              _id: '123'
            }
          ];
        }
      })
      .compile();

    tagsService = module.get(TagsService);
  });
github jkchao / blog-service / src / module / options / __test__ / options.service.spec.ts View on Github external
beforeAll(async () => {
      const module = await Test.createTestingModule({
        imports: [OptionsModule]
      })
        .overrideProvider(getModelToken('Options'))
        .useValue(mockRepository)
        .compile();

      optionsService = module.get(OptionsService);
    });
github jmcdo29 / testing-nestjs / apps / mongo-sample / src / cat / cat.service.spec.ts View on Github external
useValue: {
            new: jest.fn().mockResolvedValue(mockCat()),
            constructor: jest.fn().mockResolvedValue(mockCat()),
            find: jest.fn(),
            findOne: jest.fn(),
            update: jest.fn(),
            create: jest.fn(),
            remove: jest.fn(),
            exec: jest.fn(),
          },
        },
      ],
    }).compile();

    service = module.get(CatService);
    model = module.get>(getModelToken('Cat'));
  });
github jkchao / blog-service / src / module / comments / __test__ / comments.service.spec.ts View on Github external
beforeAll(async () => {
    const module = await Test.createTestingModule({
      imports: [CommentsModule]
    })
      .overrideProvider(getModelToken('Comments'))
      .useValue(mockRepository)
      .overrideProvider(getModelToken('Articles'))
      .useValue({})
      .overrideProvider(ArticlesSercice)
      .useValue(articlesService)
      .overrideProvider(EmailService)
      .useValue(emailService)
      .compile();

    commentsService = module.get(CommentsService);
  });
github abouroubi / nestjs-auth-jwt / src / user / user.service.spec.ts View on Github external
beforeAll(async () => {
    const mockUserModel: Partial> = {};
    const mockAuthService: Partial = {};
    const mockTokenService: Partial = {};

    const module: TestingModule = await Test.createTestingModule({
      providers: [
        UserService,
        {
          provide: getModelToken(User.modelName),
          useValue: mockUserModel,
        },
        {
          provide: AuthService,
          useValue: mockAuthService,
        },
        {
          provide: TokenService,
          useValue: mockTokenService,
        },
        MapperService,
      ],
    }).compile();
    service = module.get(UserService);
  });
  it('should be defined', () => {
github RobertYoung / mean-stack-typescript-docker / server / src / users / users.service.spec.ts View on Github external
beforeAll(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [
        UsersService,
        {
          provide: getModelToken('User'),
          useValue: {}
        }
      ]
    }).compile();
    service = module.get(UsersService);
  });
github abouroubi / nestjs-auth-jwt / src / auth / token / token.service.spec.ts View on Github external
beforeAll(async () => {
    module = await Test.createTestingModule({
      providers: [
        TokenService,
        {
          provide: getModelToken(RefreshToken.modelName),
          useFactory: () => ({
            findOneAndDelete: jest.fn(),
            findOne: jest.fn(),
            findByIdAndUpdate: jest.fn(),
            create: jest.fn(),
            deleteMany: jest.fn(),
          }),
        },
        {
          provide: AuthService,
          useFactory: () => ({}),
        },
        MapperService,
        ConfigurationService,
      ],
    }).compile();