mobitel-json-schema-template
Version:
NodeJs module for helping creation JSON schemas
113 lines (89 loc) • 3.05 kB
JavaScript
/* 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 testsAdditional() {
it('should be function', function() {
assert.equal(typeof jstArray.additional, 'function');
});
it('should return class instance', function() {
const result = jstArray.additional(true);
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().additional(...args);
} else {
result = jst.array().additional();
}
assert.equal(typeof result, 'object');
assert.equal(has(result, 'rule'), true);
assert.equal(has(result.rule, 'type'), true);
assert.equal(has(result.rule, 'additionalItems'), true);
assert.equal(result.rule.type, 'array');
assert.equal(result.rule.additionalItems, Boolean(args[0]));
};
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);
});
});
};