@@ -20,33 +20,111 @@ afterEach(() => {
20
20
} ) ;
21
21
22
22
test ( "passing validations" , ( ) => {
23
- minCheck . parse ( new File ( [ "12345" ] , "test.txt" ) ) ;
24
- maxCheck . parse ( new File ( [ "12345678" ] , "test.txt" ) ) ;
25
- mimeCheck . parse ( new File ( [ "" ] , "test.csv" , { type : "text/plain" } ) ) ;
26
- expect ( ( ) => mimeCheck . parse ( new File ( [ "" ] , "test.txt" ) ) ) . toThrow ( ) ;
27
- expect ( ( ) => mimeCheck . parse ( new File ( [ "" ] , "test.txt" , { type : "text/csv" } ) ) ) . toThrow ( ) ;
23
+ expect ( minCheck . safeParse ( new File ( [ "12345" ] , "test.txt" ) ) ) . toMatchInlineSnapshot ( `
24
+ {
25
+ "data": File {
26
+ Symbol(kHandle): Blob {},
27
+ Symbol(kLength): 5,
28
+ Symbol(kType): "",
29
+ Symbol(state): FileState {
30
+ "lastModified": 1749757007218,
31
+ "name": "test.txt",
32
+ },
33
+ },
34
+ "success": true,
35
+ }
36
+ ` ) ;
37
+ expect ( maxCheck . safeParse ( new File ( [ "12345678" ] , "test.txt" ) ) ) . toMatchInlineSnapshot ( `
38
+ {
39
+ "data": File {
40
+ Symbol(kHandle): Blob {},
41
+ Symbol(kLength): 8,
42
+ Symbol(kType): "",
43
+ Symbol(state): FileState {
44
+ "lastModified": 1749757007224,
45
+ "name": "test.txt",
46
+ },
47
+ },
48
+ "success": true,
49
+ }
50
+ ` ) ;
51
+ expect ( mimeCheck . safeParse ( new File ( [ "" ] , "test.csv" , { type : "text/plain" } ) ) ) . toMatchInlineSnapshot ( `
52
+ {
53
+ "data": File {
54
+ Symbol(kHandle): Blob {},
55
+ Symbol(kLength): 0,
56
+ Symbol(kType): "text/plain",
57
+ Symbol(state): FileState {
58
+ "lastModified": 1749757007224,
59
+ "name": "test.csv",
60
+ },
61
+ },
62
+ "success": true,
63
+ }
64
+ ` ) ;
65
+ expect ( mimeCheck . safeParse ( new File ( [ "" ] , "test.txt" ) ) ) . toThrow ( ) ;
66
+ expect ( mimeCheck . safeParse ( new File ( [ "" ] , "test.txt" , { type : "text/csv" } ) ) ) . toThrow ( ) ;
28
67
} ) ;
29
68
30
69
test ( "failing validations" , ( ) => {
31
- expect ( ( ) => minCheck . parse ( new File ( [ "1234" ] , "test.txt" ) ) ) . toThrow ( ) ;
32
- expect ( ( ) => maxCheck . parse ( new File ( [ "123456789" ] , "test.txt" ) ) ) . toThrow ( ) ;
33
- expect ( ( ) => mimeCheck . parse ( new File ( [ "" ] , "test.csv" ) ) ) . toThrow ( ) ;
34
- expect ( ( ) => mimeCheck . parse ( new File ( [ "" ] , "test.csv" , { type : "text/csv" } ) ) ) . toThrow ( ) ;
70
+ expect ( minCheck . safeParse ( new File ( [ "1234" ] , "test.txt" ) ) ) . toMatchInlineSnapshot ( `
71
+ {
72
+ "error": [ZodError: [
73
+ {
74
+ "origin": "file",
75
+ "code": "too_small",
76
+ "minimum": 5,
77
+ "path": [],
78
+ "message": "Too small: expected file to have >5 bytes"
79
+ }
80
+ ]],
81
+ "success": false,
82
+ }
83
+ ` ) ;
84
+ expect ( maxCheck . safeParse ( new File ( [ "123456789" ] , "test.txt" ) ) ) . toMatchInlineSnapshot ( `
85
+ {
86
+ "error": [ZodError: [
87
+ {
88
+ "origin": "file",
89
+ "code": "too_big",
90
+ "maximum": 8,
91
+ "path": [],
92
+ "message": "Too big: expected file to have <8 bytes"
93
+ }
94
+ ]],
95
+ "success": false,
96
+ }
97
+ ` ) ;
98
+ expect ( mimeCheck . safeParse ( new File ( [ "" ] , "test.csv" ) ) ) . toMatchInlineSnapshot ( `
99
+ {
100
+ "error": [ZodError: [
101
+ {
102
+ "code": "invalid_value",
103
+ "values": [
104
+ "text/plain",
105
+ "application/json"
106
+ ],
107
+ "path": [],
108
+ "message": "Invalid option: expected one of \\"text/plain\\"|\\"application/json\\""
109
+ }
110
+ ]],
111
+ "success": false,
112
+ }
113
+ ` ) ;
114
+ expect ( mimeCheck . safeParse ( new File ( [ "" ] , "test.csv" , { type : "text/csv" } ) ) ) . toMatchInlineSnapshot ( `
115
+ {
116
+ "error": [ZodError: [
117
+ {
118
+ "code": "invalid_value",
119
+ "values": [
120
+ "text/plain",
121
+ "application/json"
122
+ ],
123
+ "path": [],
124
+ "message": "Invalid option: expected one of \\"text/plain\\"|\\"application/json\\""
125
+ }
126
+ ]],
127
+ "success": false,
128
+ }
129
+ ` ) ;
35
130
} ) ;
36
-
37
- // test("min max getters", () => {
38
- // expect(minCheck.minSize).toEqual(5);
39
- // expect(minCheck.min(10).minSize).toEqual(10);
40
-
41
- // expect(maxCheck.maxSize).toEqual(8);
42
- // expect(maxCheck.max(6).maxSize).toEqual(6);
43
- // });
44
-
45
- // test("accept getter", () => {
46
- // expect(mimeCheck.acceptedTypes).toEqual(["text/plain", "application/json"]);
47
- // expect(mimeCheck.type(["text/plain", "application/xml"]).acceptedTypes).toEqual(["text/plain"]);
48
- // });
49
-
50
- // test("invalid mime types", () => {
51
- // expect(() => z.file().type([".txt"])).toThrow();
52
- // });
0 commit comments