UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

37 lines (33 loc) 1.66 kB
const commons = require('../../../../src/commons'); const InvalidType = require('../../../../src/commons/errors/invalid.type.error'); const Missing = require('../../../../src/commons/errors/missing.error'); describe('Check [boolean] utilities', () => { describe('Check [check] utility', () => { it.each([ [true, true, undefined], [false, false, { required: true }], [null, undefined, { required: false }] ])('should resolve [%s] when value is [%p] and options are [%p].', (expected, given, options) => { expect(commons.boolean.check(given, options)).toEqual(expected); }); it.each([ [new Missing('boolean'), undefined, undefined], [new Missing('b'), undefined, { name: 'b' }], [new Missing('boolean'), undefined, { required: true }], [new InvalidType('boolean', 'boolean'), 2, undefined], [new InvalidType('b', 'boolean'), 1, { name: 'b' }] ])('should reject [%p] when value is [%p] and options are [%p].', (error, given, options) => { expect(() => commons.boolean.check(given, options)).toThrow(error); }); }); describe('Check [resolve] utility', () => { it.each([ [{}, undefined], [{ required: true }, { required: true }] ])('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.boolean.resolve('value', given)).resolves.toEqual('called !'); expect(spyAsync).toHaveBeenCalledWith(commons.boolean.check, 'value', options); }); }); });