is-object-id.spec.js 966 B

1234567891011121314151617181920212223242526
  1. import {expect} from 'chai';
  2. import {ObjectId} from 'mongodb';
  3. import {isObjectId} from './is-object-id.js';
  4. describe('isObjectId', function () {
  5. it('returns true for a valid ObjectId string or an instance', function () {
  6. expect(isObjectId(new ObjectId())).to.be.true;
  7. expect(isObjectId(String(new ObjectId()))).to.be.true;
  8. });
  9. it('returns false for invalid values', function () {
  10. expect(isObjectId('')).to.be.false;
  11. expect(isObjectId('123')).to.be.false;
  12. expect(isObjectId(0)).to.be.false;
  13. expect(isObjectId(10)).to.be.false;
  14. expect(isObjectId(true)).to.be.false;
  15. expect(isObjectId(false)).to.be.false;
  16. expect(isObjectId({})).to.be.false;
  17. expect(isObjectId({foo: 'bar'})).to.be.false;
  18. expect(isObjectId([])).to.be.false;
  19. expect(isObjectId(['foo'])).to.be.false;
  20. expect(isObjectId(new Date())).to.be.false;
  21. expect(isObjectId(null)).to.be.false;
  22. expect(isObjectId(undefined)).to.be.false;
  23. });
  24. });