How to use @nestjs/testing - 10 common examples

To help you get started, weโ€™ve selected a few @nestjs/testing 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 ahrnee / nestjs-bff / packages / pkg-backend / lib-e2e / auth / auth.e2e-spec.js View on Github external
beforeAll(() => __awaiter(this, void 0, void 0, function* () {
        logger.trace('---- Starting Auth e2e ----');
        yield test_object_literals_constants_1.setupTestDataJwtTokens(nestjs_bff_config_1.NestjsBffConfig);
        // console.log('Auth-testData', JSON.stringify(testData, null, 2));
        const module = yield testing_1.Test.createTestingModule({
            imports: [auth_e2e_module_1.AuthE2eModule],
        }).compile();
        app = module.createNestApplication();
        yield app.init();
        httpServer = app.getHttpServer();
    }), 5 * 60 * 1000);
    //
github ahrnee / nestjs-bff / packages / pkg-backend / lib-e2e / core / global-setup-auth.js View on Github external
exports.setupAuth = (globalConfig, nestJsBffConfig) => __awaiter(this, void 0, void 0, function* () {
    const logger = logging_shared_module_1.getLogger();
    //
    // Setup
    //
    const module = yield testing_1.Test.createTestingModule({
        imports: [auth_e2e_module_1.AuthE2eModule],
    }).compile();
    const app = module.createNestApplication();
    yield app.init();
    const authenticationRepo = yield app.get(authentication_repo_1.AuthenticationRepo);
    const organizationRepo = yield app.get(organization_repo_1.OrganizationRepo);
    const userRepo = yield app.get(user_repo_1.UserRepo);
    const accessPermissionsRepo = yield app.get(access_permissions_repo_1.AccessPermissionsRepo);
    //
    // Add Data
    //
    // OrgA
    yield organizationRepo.create(test_object_literals_constants_1.testData.orgA.orgEntity, { skipAuthorization: true });
    // OrgA Admin User
    yield userRepo.create(test_object_literals_constants_1.testData.orgA.users.adminUser.userEntity, { skipAuthorization: true });
    yield authenticationRepo.create(test_object_literals_constants_1.testData.orgA.users.adminUser.authenticationEntity, { skipAuthorization: true });
github nestjs / config / tests / e2e / validation-schema.spec.ts View on Github external
it(`should validate loaded env variables`, async () => {
    try {
      const module = await Test.createTestingModule({
        imports: [AppModule.withSchemaValidation()],
      }).compile();

      app = module.createNestApplication();
      await app.init();
    } catch (err) {
      expect(err.message).toEqual(
        'Config validation error: "PORT" is required. "DATABASE_NAME" is required',
      );
    }
  });
});
github notadd / notadd / apps / nest-upms / e2e / app / baseInfo / services / logger.service.impl.e2e-spec.ts View on Github external
beforeAll(async () => {
        const module = await Test.createTestingModule({
            imports: [ApplicationModule]
        }).compile();
        app = module.createNestApplication();
        loggerService = app.get(LoggerService);
        await app.init();
    })
    it(`insert`, async () => {
github golevelup / nestjs / packages / common / src / discovery / discovery.spec.ts View on Github external
beforeEach(async () => {
    app = await Test.createTestingModule({
      imports: [DiscoveryModule, ExampleModule]
    }).compile();

    await app.init();
  });
github nestjs / bull / lib / bull.explorer.spec.ts View on Github external
it('should return the queue matching the given token', async () => {
      const queueToken = getQueueToken('test');
      const fakeQueue = 'I am a fake queue';
      const module = await Test.createTestingModule({
        imports: [BullModule.forRoot({ name: 'test' })],
      })
        .overrideProvider(queueToken)
        .useValue(fakeQueue)
        .compile();
      const moduleRef = module.get(ModuleRef);
      const queue = BullExplorer.getQueue(moduleRef, queueToken);
      expect(queue).toBeDefined();
      expect(queue).toBe(fakeQueue);
    });
  });
github visual-knight / platform-community-edition / apps / api / src / app / shared / static / static.controller.spec.ts View on Github external
beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [StaticController],
    }).compile();

    controller = module.get(StaticController);
  });
github nrwl / ngrx-workshop-app / apps / api / src / app / app.controller.spec.ts View on Github external
beforeAll(async () => {
    app = await Test.createTestingModule({
      controllers: [AppController],
      providers: [CartService, ProductService, ShippingService]
    }).compile();
  });

@nestjs/testing

Nest - modern, fast, powerful node.js web framework (@testing)

MIT
Latest version published 17 days ago

Package Health Score

91 / 100
Full package analysis

Similar packages