Skip to content

Commit 3bf834a

Browse files
authored
fix array filtering of files (#15)
1 parent bbb0b5a commit 3bf834a

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

packages/core/src/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ const forgetFiles = (data: Record<string, unknown>): Record<string, unknown> =>
321321
}
322322

323323
if (Array.isArray(value)) {
324-
newData[name] = value.filter(isFile)
324+
newData[name] = value.filter((value) => !isFile(value))
325325

326326
return
327327
}

packages/core/tests/validator.test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,68 @@ it('is valid after field has changed and successful validation has triggered', a
224224
expect(requestMade).toBe(true)
225225
expect(validator.valid()).toEqual(['name'])
226226
})
227+
228+
it('filters out files', () => {
229+
let config
230+
axios.request.mockImplementationOnce((c) => {
231+
config = c
232+
return Promise.resolve({ headers: { precognition: 'true' } })
233+
})
234+
const validator = createValidator((client) => client.post('/foo', {
235+
name: 'Tim',
236+
email: null,
237+
fruits: [
238+
'apple',
239+
'banana',
240+
new Blob([], { type: 'image/png' }),
241+
],
242+
avatar: new Blob([], { type: 'image/png' }),
243+
nested: {
244+
name: 'Tim',
245+
email: null,
246+
fruits: [
247+
'apple',
248+
'banana',
249+
new Blob([], { type: 'image/png' }),
250+
],
251+
avatar: new Blob([], { type: 'image/png' }),
252+
nested: {
253+
name: 'Tim',
254+
email: null,
255+
fruits: [
256+
'apple',
257+
'banana',
258+
new Blob([], { type: 'image/png' }),
259+
],
260+
avatar: new Blob([], { type: 'image/png' }),
261+
}
262+
}
263+
}))
264+
265+
validator.validate('text', 'Tim')
266+
267+
expect(config.data).toEqual({
268+
name: 'Tim',
269+
email: null,
270+
fruits: [
271+
'apple',
272+
'banana',
273+
],
274+
nested: {
275+
name: 'Tim',
276+
email: null,
277+
fruits: [
278+
'apple',
279+
'banana',
280+
],
281+
nested: {
282+
name: 'Tim',
283+
email: null,
284+
fruits: [
285+
'apple',
286+
'banana',
287+
],
288+
}
289+
}
290+
})
291+
})

0 commit comments

Comments
 (0)