not-implemented-error.spec.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import {expect} from 'chai';
  2. import {format} from '@e22m4u/js-format';
  3. import {NotImplementedError} from './not-implemented-error.js';
  4. describe('NotImplementedError', function () {
  5. it('inherits from Error class', function () {
  6. const error = new NotImplementedError();
  7. expect(error).to.be.instanceof(Error);
  8. });
  9. it('sets a given message', function () {
  10. const error = new NotImplementedError('This is the Error');
  11. expect(error.message).to.be.eq('This is the Error');
  12. });
  13. it('interpolates a given pattern with variables', function () {
  14. const throwable = v => () => {
  15. throw new NotImplementedError('%v', v);
  16. };
  17. const error = v => format('%s', v);
  18. expect(throwable('str')).to.throw(error('"str"'));
  19. expect(throwable('')).to.throw(error('""'));
  20. expect(throwable(10)).to.throw(error('10'));
  21. expect(throwable(0)).to.throw(error(0));
  22. expect(throwable(true)).to.throw(error('true'));
  23. expect(throwable(false)).to.throw(error('false'));
  24. expect(throwable({})).to.throw(error('Object'));
  25. expect(throwable([])).to.throw(error('Array'));
  26. expect(throwable(undefined)).to.throw(error('undefined'));
  27. expect(throwable(null)).to.throw(error('null'));
  28. expect(throwable(() => undefined)).to.throw(error('Function'));
  29. });
  30. });