objectid-utils.spec.ts 913 B

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