UNPKG

@e22m4u/js-repository

Version:

Реализация репозитория для работы с базами данных в Node.js

34 lines (30 loc) 1.3 kB
import {expect} from 'chai'; import {format} from '@e22m4u/js-format'; import {InvalidArgumentError} from './invalid-argument-error.js'; describe('InvalidArgumentError', function () { it('inherits from Error class', function () { const error = new InvalidArgumentError(); expect(error).to.be.instanceof(Error); }); it('sets a given message', function () { const error = new InvalidArgumentError('This is the Error'); expect(error.message).to.be.eq('This is the Error'); }); it('interpolates a given pattern with variables', function () { const throwable = v => () => { throw new InvalidArgumentError('%v', v); }; const error = v => format('%s', v); expect(throwable('str')).to.throw(error('"str"')); expect(throwable('')).to.throw(error('""')); expect(throwable(10)).to.throw(error('10')); expect(throwable(0)).to.throw(error(0)); expect(throwable(true)).to.throw(error('true')); expect(throwable(false)).to.throw(error('false')); expect(throwable({})).to.throw(error('Object')); expect(throwable([])).to.throw(error('Array')); expect(throwable(undefined)).to.throw(error('undefined')); expect(throwable(null)).to.throw(error('null')); expect(throwable(() => undefined)).to.throw(error('Function')); }); });