Skip to content

Commit

Permalink
fix: jest toMatchSnapshot fix (date)
Browse files Browse the repository at this point in the history
  • Loading branch information
izatop committed Mar 5, 2020
1 parent 6595f50 commit 7460f7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
10 changes: 5 additions & 5 deletions packages/test/src/unit/Validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import {assert, isBoolean, isNumber, isString} from "@typesafeunit/util";

interface IChildSample {
name: string;
date?: Date;
date?: string;
}

interface ISample {
v: number;
b: boolean;
child: IChildSample;
nullable: Date | null;
nullable: string | null;
}

const validSample: ISample = {
v: 1,
b: true,
child: {
name: "Bob",
date: new Date("2020-01-01T00:00:00.000Z"),
date: "2020-01-01T00:00:00.000Z",
},
nullable: null,
};
Expand All @@ -28,13 +28,13 @@ const invalidSample = {
b: true,
child: {
name: 123,
date: new Date("2020-01-01T00:00:00.000Z"),
date: "2020-01-01T00:00:00.000Z",
},
nullable: true,
};

test("Validation", async () => {
const validateDate = (v: any) => assert(v instanceof Date);
const validateDate = (v: any) => assert(!!new Date(v));
const childValidationSchema = new ValidationSchema<IChildSample>();
childValidationSchema
.add("date", {validator: validateDate, required: false})
Expand Down
12 changes: 4 additions & 8 deletions packages/test/src/unit/__snapshots__/Validation.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Object {
"child": Object {
"valid": true,
"value": Object {
"date": 1999-12-31T21:00:00.000Z,
"date": "2020-01-01T00:00:00.000Z",
"name": "Bob",
},
},
Expand Down Expand Up @@ -50,7 +50,7 @@ Object {
"validation": Object {
"date": Object {
"valid": true,
"value": 1999-12-31T21:00:00.000Z,
"value": "2020-01-01T00:00:00.000Z",
},
"name": Object {
"error": [Error: Assertion fails],
Expand All @@ -63,16 +63,12 @@ Object {
},
},
"value": Object {
"date": 1999-12-31T21:00:00.000Z,
"date": "2020-01-01T00:00:00.000Z",
"name": 123,
},
},
"nullable": Object {
"error": [Error: Assertion fails],
"message": undefined,
"nullable": true,
"required": true,
"valid": false,
"valid": true,
"value": true,
},
"v": Object {
Expand Down

0 comments on commit 7460f7b

Please sign in to comment.