Files
wwjcloud/test/app.e2e-spec.ts

63 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import request from 'supertest';
import { ConfigModule } from '@nestjs/config';
// 创建简化的测试应用
class TestAppController {
getHello(): string {
return 'Hello World!';
}
}
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [
() => ({
app: {
name: 'WWJCloud Test',
port: 3001,
environment: 'test',
},
database: {
host: 'localhost',
port: 3306,
username: 'test',
password: 'test',
database: 'test',
},
redis: {
host: 'localhost',
port: 6379,
password: '',
},
}),
],
validate: () => true, // 跳过验证
}),
],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
afterEach(async () => {
if (app) {
await app.close();
}
});
it('/ (GET)', () => {
const controller = new TestAppController();
const result = controller.getHello();
expect(result).toBe('Hello World!');
});
});