UNPKG

mobitel-json-schema-template

Version:
113 lines (89 loc) 3.01 kB
/* eslint no-undefined: 0, func-names: 0, prefer-arrow-callback: 0, max-nested-callbacks: 0 */ const assert = require('assert'); const jst = require('../../index.js'); const jstArray = jst.array(); const has = function objHasProperty(obj, property) { return Object.prototype.hasOwnProperty.call(obj, property); }; module.exports = function testsBoolean() { it('should be function', function() { assert.equal(typeof jstArray.unique, 'function'); }); it('should return class instance', function() { const result = jstArray.unique(); assert.equal(typeof result, 'object'); assert.equal((result instanceof Object), true); assert.equal((result instanceof jstArray.constructor), true); assert.equal((result.constructor === jstArray.constructor), true); }); describe('should return object when', function() { const test = (...args) => { let result; if (args.length > 0) { result = jst.array().unique(...args); } else { result = jst.array().unique(); } assert.equal(typeof result, 'object'); assert.equal(has(result, 'rule'), true); assert.equal(has(result.rule, 'type'), true); assert.equal(has(result.rule, 'uniqueItems'), true); assert.equal(result.rule.type, 'array'); assert.equal(result.rule.uniqueItems, true); }; it('call without arguments', function() { test(); }); it('call with null', function() { test(null); }); it('call with true', function() { test(true); }); it('call with false', function() { test(false); }); it('call with NaN', function() { test(NaN); }); it('call with Function', function() { test(() => 10); }); it('call with Number', function() { test(1); }); it('call with Number as 0', function() { test(0); }); it('call with float Number', function() { test(1.2); }); it('call with String', function() { test('string'); }); it('call with empty String', function() { test(''); }); it('call with Array', function() { test([1, 2, 3]); }); it('call with empty Array', function() { test([]); }); it('call with Object', function() { test({key: 'value'}); }); it('call with empty Object', function() { test({}); }); it('call with Symbol', function() { test(Symbol('test')); }); it('call with RegExp', function() { test(/^\d*$/); }); it('call with multiple arguments', function() { test([1, 2, 3], 'value', 1, null); }); }); };