本文整理匯總了TypeScript中@nestjs/common.INestApplication類的典型用法代碼示例。如果您正苦於以下問題:TypeScript INestApplication類的具體用法?TypeScript INestApplication怎麽用?TypeScript INestApplication使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了INestApplication類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: describe
describe('NATS transport', () => {
let server;
let app: INestApplication;
beforeEach(async () => {
const module = await Test.createTestingModule({
controllers: [NatsBroadcastController],
}).compile();
server = express();
app = module.createNestApplication(server);
app.connectMicroservice({
transport: Transport.NATS,
});
app.connectMicroservice({
transport: Transport.NATS,
});
await app.startAllMicroservicesAsync();
await app.init();
});
it(`Broadcast (2 subscribers)`, () => {
return request(server)
.get('/broadcast')
.expect(200, '2');
});
afterEach(async () => {
await app.close();
});
});
示例2: describe
describe('Cats', () => {
let app: INestApplication;
let catsService = { findAll: () => ['test'] };
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [CatsModule],
})
.overrideProvider(CatsService)
.useValue(catsService)
.compile();
app = module.createNestApplication();
await app.init();
});
it(`/GET cats`, () => {
return request(app.getHttpServer())
.get('/cats')
.expect(200)
.expect({
data: catsService.findAll(),
});
});
afterAll(async () => {
await app.close();
});
});
示例3: beforeEach
beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [AsyncOptionsClassModule],
}).compile();
app = module.createNestApplication();
server = app.getHttpServer();
await app.init();
});
示例4: AuthGuard
it(`should prevent access (unauthorized)`, async () => {
app = (await createTestModule(
new AuthGuard(),
)).createNestApplication();
await app.init();
return request(app.getHttpServer())
.get('/hello')
.expect(401);
});
示例5: OverrideInterceptor
it(`should transform response (sync)`, async () => {
app = (await createTestModule(
new OverrideInterceptor(),
)).createNestApplication();
await app.init();
return request(app.getHttpServer())
.get('/hello')
.expect(200, RETURN_VALUE);
});
示例6: TransformInterceptor
it(`should map response (stream)`, async () => {
app = (await createTestModule(
new TransformInterceptor(),
)).createNestApplication();
await app.init();
return request(app.getHttpServer())
.get('/hello/async')
.expect(200, { data: 'Hello world!' });
});
示例7: beforeEach
beforeEach(async () => {
const module = await Test.createTestingModule({
controllers: [ErrorsController],
})
.compile();
app = module.createNestApplication();
server = app.getHttpServer();
await app.init();
});
示例8: beforeEach
beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [ApplicationModule],
}).compile();
server = express();
app = module.createNestApplication(server);
app.connectMicroservice({
transport: Transport.TCP,
});
await app.startAllMicroservicesAsync();
await app.init();
});
示例9: beforeEach
beforeEach(async () => {
const module = await Test.createTestingModule({
controllers: [RedisController],
}).compile();
server = express();
app = module.createNestApplication(server);
app.connectMicroservice({
transport: Transport.REDIS,
});
await app.startAllMicroservicesAsync();
await app.init();
});
示例10: request
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/users')
.auth('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Im1hcnRpbkB0ZWxlcmlrYWNhZGVteS5jb20iLCJpc0FkbWluIjp0cnVlLCJpYXQiOjE1NDQzOTYxMzcsImV4cCI6MTU0NTAwMDkzN30.fqmWkUcrADb2c5XeyO6FIerau10VWvqSdkSeHWnuqq0', { type: 'bearer' })
.expect(200)
.expect('[{"id":1,"email":"martin@telerikacademy.com","password":"123","avatarUrl":"public\\\\images\\\\default.png","isAdmin":true}]');
});