RandomGeneratorUtils.spec.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { assert } from 'chai';
  2. import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
  3. import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
  4. import { IRandomGenerator } from '../../../src/interfaces/utils/IRandomGenerator';
  5. import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
  6. describe('RandomGeneratorUtils', () => {
  7. describe('getRandomVariableName (length: number = 6): string', () => {
  8. let randomGenerator: IRandomGenerator,
  9. randomVariableName: string,
  10. regExp: RegExp;
  11. before(() => {
  12. const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
  13. inversifyContainerFacade.load('', {});
  14. randomGenerator = inversifyContainerFacade.get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator)
  15. });
  16. describe('variant #1: string with random variable of length `4`', () => {
  17. before(() => {
  18. randomVariableName = randomGenerator.getRandomVariableName(4);
  19. regExp = /^_0x(\w){4}$/;
  20. });
  21. it('should return random variable name', () => {
  22. assert.match(randomVariableName, regExp);
  23. })
  24. });
  25. describe('variant #2: string with random variable of length `6`', () => {
  26. before(() => {
  27. randomVariableName = randomGenerator.getRandomVariableName(6);
  28. regExp = /^_0x(\w){4,6}$/;
  29. });
  30. it('should return random variable name', () => {
  31. assert.match(randomVariableName, regExp);
  32. })
  33. });
  34. });
  35. });