UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

38 lines (33 loc) 1.66 kB
const commons = require('../../../../src/commons'); const InvalidClass = require('../../../../src/commons/errors/invalid.class.error'); const Missing = require('../../../../src/commons/errors/missing.error'); describe('Check [object] utilities', () => { describe('Check [check] utility', () => { it.each([[new Error('yeah!'), { _class: Error }]])( 'should resolve given when value given [%p] and options are [%p].', (given, options) => { expect(commons.object.check(given, options)).toBe(given); } ); it('should reject when given nothing.', () => { expect(() => commons.object.check()).toThrow(new Missing('instance')); }); it.each([ [new Missing('i'), undefined, { name: 'i', className: 'c', _class: Error }], [new InvalidClass('i', 'c'), 1, { name: 'i', className: 'c', _class: Error }] ])('should reject [%p] when value is [%p] and options are [%p].', (error, given, options) => { expect(() => commons.object.check(given, options)).toThrow(error); }); }); describe('Check [resolve] utility', () => { it.each([ [{}, undefined], [{ name: 'toto' }, { name: 'toto' }] ])('should encapsulate in a promise the check function when given options is [%p].', (options, given) => { const spyAsync = jest.spyOn(commons.promise, 'async').mockResolvedValue('called !'); expect(commons.object.resolve('value', given)).resolves.toEqual('called !'); expect(spyAsync).toHaveBeenCalledWith(commons.object.check, 'value', options); jest.spyOn(commons.promise, 'async').mockRestore(); }); }); });