test(): add compare element and internal core module unit tests

This commit is contained in:
Kamil Myśliwiec
2021-07-16 10:31:47 +02:00
parent 08d19a6f27
commit f3c17e7588
2 changed files with 39 additions and 4 deletions

View File

@@ -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,
);
});
});

View File

@@ -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;
});
});