objectid-utils.spec.ts 883 B

123456789101112131415161718192021222324
  1. import ObjectId from 'bson-objectid';
  2. import { isValidObjectId } from './objectid-utils';
  3. describe('isValidObjectId', () => {
  4. describe.concurrent.each`
  5. arg | expected
  6. ${undefined} | ${false}
  7. ${null} | ${false}
  8. ${'geeks'} | ${false}
  9. ${'toptoptoptop'} | ${false}
  10. ${'geeksfogeeks'} | ${false}
  11. ${'594ced02ed345b2b049222c5'} | ${true}
  12. ${new ObjectId('594ced02ed345b2b049222c5')} | ${true}
  13. `('should return $expected', ({ arg, expected }) => {
  14. test(`when the argument is '${arg}'`, async () => {
  15. // when:
  16. const result = isValidObjectId(arg);
  17. // then:
  18. expect(result).toBe(expected);
  19. });
  20. });
  21. });