mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { expect } from 'chai';
|
|
import { ApplicationConfig } from '../application-config';
|
|
import { NestContainer } from '../injector/container';
|
|
import { GraphInspector } from '../inspector/graph-inspector';
|
|
import { NestApplication } from '../nest-application';
|
|
import { NoopHttpAdapter } from './utils/noop-adapter.spec';
|
|
|
|
describe('NestApplication', () => {
|
|
describe('Hybrid Application', () => {
|
|
class Interceptor {
|
|
public intercept(context, next) {
|
|
return next();
|
|
}
|
|
}
|
|
it('default should use new ApplicationConfig', () => {
|
|
const applicationConfig = new ApplicationConfig();
|
|
const container = new NestContainer(applicationConfig);
|
|
const instance = new NestApplication(
|
|
container,
|
|
new NoopHttpAdapter({}),
|
|
applicationConfig,
|
|
new GraphInspector(container),
|
|
{},
|
|
);
|
|
instance.useGlobalInterceptors(new Interceptor());
|
|
const microservice = instance.connectMicroservice({});
|
|
expect((instance as any).config.getGlobalInterceptors().length).to.equal(
|
|
1,
|
|
);
|
|
expect(
|
|
(microservice as any).applicationConfig.getGlobalInterceptors().length,
|
|
).to.equal(0);
|
|
});
|
|
it('should inherit existing ApplicationConfig', () => {
|
|
const applicationConfig = new ApplicationConfig();
|
|
const container = new NestContainer(applicationConfig);
|
|
const instance = new NestApplication(
|
|
container,
|
|
new NoopHttpAdapter({}),
|
|
applicationConfig,
|
|
new GraphInspector(container),
|
|
{},
|
|
);
|
|
instance.useGlobalInterceptors(new Interceptor());
|
|
const microservice = instance.connectMicroservice(
|
|
{},
|
|
{ inheritAppConfig: true },
|
|
);
|
|
expect((instance as any).config.getGlobalInterceptors().length).to.equal(
|
|
1,
|
|
);
|
|
expect(
|
|
(microservice as any).applicationConfig.getGlobalInterceptors().length,
|
|
).to.equal(1);
|
|
});
|
|
});
|
|
});
|