Skip to content

Commit a84b47c

Browse files
authored
feat: Add in file type testing (#5)
1 parent 5ee76bb commit a84b47c

File tree

5 files changed

+288
-7
lines changed

5 files changed

+288
-7
lines changed

packages/arktype-utils/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@vitest/coverage-v8": "^1.2.2",
2323
"arktype": "^1.0.28-alpha",
2424
"eslint": "^7.11.0",
25+
"jsdom": "^24.0.0",
2526
"tsup": "^8.0.1",
2627
"typescript": "^5.3.3",
2728
"vitest": "^1.1.3"

packages/arktype-utils/src/formData.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ describe('formDataToObject', () => {
9696
});
9797

9898
describe('validateFormData', () => {
99+
const fileType = type(['instanceof', File]);
99100
it('Validates simple object', () => {
100101
const schema = type({
101102
name: 'string',
@@ -118,16 +119,19 @@ describe('validateFormData', () => {
118119
});
119120

120121
it('Validates a more complex schema', () => {
122+
const f = new File([], 'file.txt');
121123
const fd = new FormData();
122124
fd.append('emails', 'jim@jim.jim');
123125
fd.append('emails', 'bob@bob.email');
124126
fd.append('something', 'true');
125127
fd.append('something-else', '101n');
128+
fd.append('file-upload', f);
126129

127130
const passSchema = type({
128131
emails: 'email[]',
129132
something: 'boolean',
130133
'something-else': 'bigint',
134+
'file-upload': fileType,
131135
});
132136

133137
const obj = validateFormData(fd, passSchema);
@@ -136,6 +140,7 @@ describe('validateFormData', () => {
136140
emails: ['jim@jim.jim', 'bob@bob.email'],
137141
something: true,
138142
'something-else': 101n,
143+
'file-upload': f,
139144
});
140145

141146
fd.append('emails', 'bad@');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
// Need this to use File in the tests
6+
environment: 'jsdom',
7+
},
8+
});

packages/typescript-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jhecht/typescript-config",
3-
"version": "0.0.0",
3+
"version": "0.1.0",
44
"private": true,
55
"license": "MIT",
66
"publishConfig": {

0 commit comments

Comments
 (0)