|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const { test } = require('node:test') |
| 4 | +const build = require('..') |
| 5 | + |
| 6 | +test('additionalProperties: false', (t) => { |
| 7 | + t.plan(1) |
| 8 | + const stringify = build({ |
| 9 | + title: 'additionalProperties', |
| 10 | + type: 'object', |
| 11 | + properties: { |
| 12 | + foo: { |
| 13 | + type: 'string' |
| 14 | + } |
| 15 | + }, |
| 16 | + additionalProperties: false |
| 17 | + }) |
| 18 | + |
| 19 | + const obj = { foo: 'a', bar: 'b', baz: 'c' } |
| 20 | + t.assert.equal(stringify(obj), '{"foo":"a"}') |
| 21 | +}) |
| 22 | + |
| 23 | +test('additionalProperties: {}', (t) => { |
| 24 | + t.plan(1) |
| 25 | + const stringify = build({ |
| 26 | + title: 'additionalProperties', |
| 27 | + type: 'object', |
| 28 | + properties: { |
| 29 | + foo: { |
| 30 | + type: 'string' |
| 31 | + } |
| 32 | + }, |
| 33 | + additionalProperties: {} |
| 34 | + }) |
| 35 | + |
| 36 | + const obj = { foo: 'a', bar: 'b', baz: 'c' } |
| 37 | + t.assert.equal(stringify(obj), '{"foo":"a","bar":"b","baz":"c"}') |
| 38 | +}) |
| 39 | + |
| 40 | +test('additionalProperties: {type: string}', (t) => { |
| 41 | + t.plan(1) |
| 42 | + const stringify = build({ |
| 43 | + title: 'additionalProperties', |
| 44 | + type: 'object', |
| 45 | + properties: { |
| 46 | + foo: { |
| 47 | + type: 'string' |
| 48 | + } |
| 49 | + }, |
| 50 | + additionalProperties: { |
| 51 | + type: 'string' |
| 52 | + } |
| 53 | + }) |
| 54 | + |
| 55 | + const obj = { foo: 'a', bar: 'b', baz: 'c' } |
| 56 | + t.assert.equal(stringify(obj), '{"foo":"a","bar":"b","baz":"c"}') |
| 57 | +}) |
0 commit comments