diff --git a/packages/app/test/src/__snapshots__/InputState.test.ts.snap b/packages/app/test/src/__snapshots__/InputState.test.ts.snap index 984e21fe..0e24c64a 100644 --- a/packages/app/test/src/__snapshots__/InputState.test.ts.snap +++ b/packages/app/test/src/__snapshots__/InputState.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Route Fails 1`] = `[Error: Assertion failed]`; +exports[`Route Fails 1`] = `[Error: Assertion failed: payload]`; exports[`Route Success 1`] = ` Object { diff --git a/packages/input/src/Type/Fields.ts b/packages/input/src/Type/Fields.ts index f1317f4a..11cb1e7b 100644 --- a/packages/input/src/Type/Fields.ts +++ b/packages/input/src/Type/Fields.ts @@ -36,6 +36,7 @@ export class Fields> extends TypeAbstract { this.assert(isObject(payload), `Wrong payload: ${this.name} expected`, payload); + const errorFields: string[] = []; const entries: [string, any][] = []; const validations = new Map(); for (const [field, type] of Object.entries(this.#fields)) { @@ -49,6 +50,8 @@ export class Fields> extends TypeAbstract> extends TypeAbstract 0) { throw new AssertionObjectError( - "Assertion failed", + `Assertion failed: ${errorFields.join(", ")}`, this, payload, entriesReverse([...validations.entries()]), diff --git a/packages/input/src/interfaces.ts b/packages/input/src/interfaces.ts index eb5c6030..3eadda53 100644 --- a/packages/input/src/interfaces.ts +++ b/packages/input/src/interfaces.ts @@ -1,4 +1,4 @@ -import {Fields, List, Union} from "./Type"; +import {Fields, List, Union, RecordType} from "./Type"; import {TypeAbstract} from "./TypeAbstract"; export type FieldFn = () => T; @@ -10,7 +10,7 @@ export type FieldsSchema = { : T[K] extends Date ? FieldType> : T[K] extends Record - ? FieldType | Union> + ? FieldType | Union | typeof RecordType> : FieldType>; }; diff --git a/packages/input/test/src/Main.test.ts b/packages/input/test/src/Main.test.ts index ab3bc03c..1b747c91 100644 --- a/packages/input/test/src/Main.test.ts +++ b/packages/input/test/src/Main.test.ts @@ -133,10 +133,15 @@ describe("Test Input", () => { }); test("RecordType", async () => { - const plainObject = {foo: 1, bar: 2}; - await expect(validate(RecordType, plainObject)) + const dataset = {id: Math.random(), data: {foo: 1, bar: 2}}; + const schema = new Fields<{id: number; data: Record}>({ + id: Float, + data: RecordType, + }); + + await expect(validate(schema, dataset)) .resolves - .toEqual(plainObject); + .toEqual(dataset); await expect(validate(RecordType, null)) .rejects diff --git a/packages/input/test/src/__snapshots__/Main.test.ts.snap b/packages/input/test/src/__snapshots__/Main.test.ts.snap index 9777ed9e..df785e8f 100644 --- a/packages/input/test/src/__snapshots__/Main.test.ts.snap +++ b/packages/input/test/src/__snapshots__/Main.test.ts.snap @@ -19,7 +19,7 @@ Object { }, }, "index": 1, - "message": "Assertion failed", + "message": "Assertion failed: children, links", "payload": Object { "age": 12, "children": 1, @@ -41,7 +41,7 @@ Object { }, }, "index": 2, - "message": "Assertion failed", + "message": "Assertion failed: name, links", "payload": Object { "age": 3, }, @@ -81,7 +81,7 @@ Object { "type": "Int", }, }, - "message": "Assertion failed", + "message": "Assertion failed: age", "payload": Object { "links": Array [ "a", @@ -91,7 +91,7 @@ Object { "type": "Human", }, }, - "message": "Assertion failed", + "message": "Assertion failed: name, children, parent", "payload": Object { "age": 32, "children": Array [