feature: make typescript starter more robust
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
|
||||
describe('AppController', () => {
|
||||
let app: TestingModule;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
}).compile();
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
const appController = app.get<AppController>(AppController);
|
||||
expect(appController.root()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -2,8 +2,8 @@ import { Get, Controller } from '@nestjs/common';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
@Get()
|
||||
root(): string {
|
||||
@Get()
|
||||
root(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ import { AppController } from './app.controller';
|
||||
controllers: [AppController],
|
||||
components: [],
|
||||
})
|
||||
export class ApplicationModule {}
|
||||
export class AppModule {}
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { ApplicationModule } from './app.module';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(ApplicationModule);
|
||||
await app.listen(3000);
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { ApplicationModule } from './app.module';
|
||||
|
||||
describe('Basic E2E Test', () => {
|
||||
const server = express();
|
||||
|
||||
beforeAll(async () => {
|
||||
const module = await Test.createTestingModule({
|
||||
modules: [ApplicationModule]
|
||||
})
|
||||
.compile();
|
||||
|
||||
const app = module.createNestApplication(server);
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/GET /', () => {
|
||||
return request(server)
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user