mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 15:08:37 +00:00
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { INestApplication } from '@nestjs/common';
|
|
import { Test } from '@nestjs/testing';
|
|
import { expect } from 'chai';
|
|
import * as request from 'supertest';
|
|
import { RequestChainModule } from '../src/request-chain/request-chain.module';
|
|
import { RequestChainService } from '../src/request-chain/request-chain.service';
|
|
|
|
describe('Request scope (modules propagation)', () => {
|
|
let server;
|
|
let app: INestApplication;
|
|
|
|
before(async () => {
|
|
const module = await Test.createTestingModule({
|
|
imports: [RequestChainModule],
|
|
}).compile();
|
|
|
|
app = module.createNestApplication();
|
|
server = app.getHttpServer();
|
|
await app.init();
|
|
});
|
|
|
|
describe('when service from parent module is request scoped', () => {
|
|
before(async () => {
|
|
const performHttpCall = end =>
|
|
request(server)
|
|
.get('/hello')
|
|
.end(err => {
|
|
if (err) return end(err);
|
|
end();
|
|
});
|
|
await new Promise<any>(resolve => performHttpCall(resolve));
|
|
await new Promise<any>(resolve => performHttpCall(resolve));
|
|
await new Promise<any>(resolve => performHttpCall(resolve));
|
|
});
|
|
|
|
it(`should not fail`, () => {
|
|
expect(RequestChainService.COUNTER).to.be.eql(3);
|
|
});
|
|
});
|
|
|
|
after(async () => {
|
|
await app.close();
|
|
});
|
|
});
|