本文整理汇总了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}]');
});