mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
test(): add compare element and internal core module unit tests
This commit is contained in:
@@ -1,13 +1,39 @@
|
||||
import { ClassProvider, FactoryProvider } from '@nestjs/common';
|
||||
import { expect } from 'chai';
|
||||
import { ExternalContextCreator } from '../../helpers/external-context-creator';
|
||||
import { HttpAdapterHost } from '../../helpers/http-adapter-host';
|
||||
import { LazyModuleLoader, ModulesContainer } from '../../injector';
|
||||
import { NestContainer } from '../../injector/container';
|
||||
import { InternalCoreModule } from '../../injector/internal-core-module';
|
||||
import { InternalCoreModuleFactory } from '../../injector/internal-core-module-factory';
|
||||
|
||||
describe('InternalCoreModuleFactory', () => {
|
||||
it('should return the interal core module definition', () => {
|
||||
expect(
|
||||
InternalCoreModuleFactory.create(new NestContainer(), null, null, null)
|
||||
.module,
|
||||
).to.equal(InternalCoreModule);
|
||||
const moduleDefinition = InternalCoreModuleFactory.create(
|
||||
new NestContainer(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
expect(moduleDefinition.module).to.equal(InternalCoreModule);
|
||||
|
||||
const providedInjectables = moduleDefinition.providers.map(
|
||||
item => (item as ClassProvider | FactoryProvider).provide,
|
||||
);
|
||||
expect(providedInjectables).to.deep.equal([
|
||||
ExternalContextCreator,
|
||||
ModulesContainer,
|
||||
HttpAdapterHost,
|
||||
HttpAdapterHost.name,
|
||||
LazyModuleLoader,
|
||||
]);
|
||||
|
||||
const lazyModuleLoaderProvider = moduleDefinition.providers.find(
|
||||
item => (item as FactoryProvider)?.provide === LazyModuleLoader,
|
||||
) as FactoryProvider;
|
||||
expect(lazyModuleLoaderProvider.useFactory()).to.be.instanceOf(
|
||||
LazyModuleLoader,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { expect } from 'chai';
|
||||
import { compareElementAt } from '../../utils/compare-element.util';
|
||||
|
||||
describe('compareElementAt', () => {
|
||||
it('should compare elements at the specific position in arrays', () => {
|
||||
expect(compareElementAt([0, 1, 0], [2, 1, 7], 1)).to.be.true;
|
||||
expect(compareElementAt([0, 1, 0], [2, 0, 7], 1)).to.be.false;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user