aboutsummaryrefslogtreecommitdiff
path: root/test/json-schema.test.js
diff options
context:
space:
mode:
authorCashew <52880648+Scrub1492@users.noreply.github.com>2024-01-06 08:00:37 +0700
committerGitHub <noreply@github.com>2024-01-06 01:00:37 +0000
commit60276d41ffd90044acc2f95e70b9b0c9a770417a (patch)
tree0bd08871a14d025007ba5453691b27976c39d77d /test/json-schema.test.js
parentd17ca4b2ff6e6f359dc5ea72c133f99fb016effd (diff)
Test updates (#501)
* update tests * japanese-util updates * update json-schema tests
Diffstat (limited to 'test/json-schema.test.js')
-rw-r--r--test/json-schema.test.js52
1 files changed, 34 insertions, 18 deletions
diff --git a/test/json-schema.test.js b/test/json-schema.test.js
index 0c1a483b..4773e898 100644
--- a/test/json-schema.test.js
+++ b/test/json-schema.test.js
@@ -18,7 +18,7 @@
/* eslint-disable no-multi-spaces */
-import {expect, test} from 'vitest';
+import {describe, expect, test} from 'vitest';
import {parseJson} from '../dev/json.js';
import {JsonSchema} from '../ext/js/data/json-schema.js';
@@ -61,7 +61,7 @@ function clone(value) {
/** */
function testValidate1() {
- test('Validate1', () => {
+ describe('Validate1', () => {
/** @type {import('ext/json-schema').Schema} */
const schema = {
allOf: [
@@ -112,17 +112,19 @@ function testValidate1() {
);
};
- for (let i = -111; i <= 111; i++) {
- const actual = schemaValidate(schema, i);
- const expected = jsValidate(i);
- expect(actual).toStrictEqual(expected);
- }
+ test('works as expected', () => {
+ for (let i = -111; i <= 111; i++) {
+ const actual = schemaValidate(schema, i);
+ const expected = jsValidate(i);
+ expect(actual).toStrictEqual(expected);
+ }
+ });
});
}
/** */
function testValidate2() {
- test('Validate2', () => {
+ describe('Validate2', () => {
/** @type {{schema: import('ext/json-schema').Schema, inputs: {expected: boolean, value: unknown}[]}[]} */
const data = [
// String tests
@@ -517,19 +519,19 @@ function testValidate2() {
}
];
- for (const {schema, inputs} of data) {
- for (const {expected, value} of inputs) {
+ describe.each(data)('Schema %#', ({schema, inputs}) => {
+ test.each(inputs)(`schemaValidate(${schema}, $value) -> $expected`, ({expected, value}) => {
const actual = schemaValidate(schema, value);
expect(actual).toStrictEqual(expected);
- }
- }
+ });
+ });
});
}
/** */
function testGetValidValueOrDefault1() {
- test('GetValidValueOrDefault1', () => {
+ describe('GetValidValueOrDefault1', () => {
/** @type {{schema: import('ext/json-schema').Schema, inputs: [value: unknown, expected: unknown][]}[]} */
const data = [
// Test value defaulting on objects with additionalProperties=false
@@ -875,19 +877,19 @@ function testGetValidValueOrDefault1() {
}
];
- for (const {schema, inputs} of data) {
- for (const [value, expected] of inputs) {
+ describe.each(data)('Schema %#', ({schema, inputs}) => {
+ test.each(inputs)(`getValidValueOrDefault(${schema}, %o) -> %o`, (value, expected) => {
const actual = getValidValueOrDefault(schema, value);
expect(actual).toStrictEqual(expected);
- }
- }
+ });
+ });
});
}
/** */
function testProxy1() {
- test('Proxy1', () => {
+ describe('Proxy1', () => {
/** @type {{schema: import('ext/json-schema').Schema, tests: {error: boolean, value?: import('ext/json-schema').Value, action: (value: import('core').SafeAny) => void}[]}[]} */
const data = [
// Object tests
@@ -1018,6 +1020,20 @@ function testProxy1() {
}
];
+ describe.each(data)('Schema %#', ({schema, tests}) => {
+ test.each(tests)('proxy %#', ({error, value, action}) => {
+ if (typeof value === 'undefined') { value = getValidValueOrDefault(schema, void 0); }
+ value = clone(value);
+ expect(schemaValidate(schema, value)).toBe(true);
+ const valueProxy = createProxy(schema, value);
+ if (error) {
+ expect(() => action(valueProxy)).toThrow();
+ } else {
+ expect(() => action(valueProxy)).not.toThrow();
+ }
+ });
+ });
+
for (const {schema, tests} of data) {
for (let {error, value, action} of tests) {
if (typeof value === 'undefined') { value = getValidValueOrDefault(schema, void 0); }