-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
/
express.spec.ts
48 lines (41 loc) 路 1.2 KB
/
express.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { NestExpressApplication } from '@nestjs/platform-express';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as request from 'supertest';
import { ExpressModule } from '../src/express.module';
describe('Raw body (Express Application)', () => {
let app: NestExpressApplication;
const body = '{ "amount":0.0 }';
beforeEach(async () => {
const moduleFixture = await Test.createTestingModule({
imports: [ExpressModule],
}).compile();
app = moduleFixture.createNestApplication<NestExpressApplication>({
rawBody: true,
});
});
it('should return exact post body', async () => {
await app.init();
const response = await request(app.getHttpServer())
.post('/')
.set('Content-Type', 'application/json')
.send(body)
.expect(201);
expect(response.body).to.eql({
parsed: {
amount: 0,
},
raw: '{ "amount":0.0 }',
});
});
it('should work if post body is empty', async () => {
await app.init();
await request(app.getHttpServer())
.post('/')
.set('Content-Type', 'application/json')
.expect(201);
});
afterEach(async () => {
await app.close();
});
});