31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import { isWebFileLike } from '@/lib/web-file'
|
|
|
|
describe('isWebFileLike', () => {
|
|
it('recognizes a multipart file without relying on a global File constructor', () => {
|
|
const originalFile = globalThis.File
|
|
Object.defineProperty(globalThis, 'File', { configurable: true, value: undefined })
|
|
|
|
try {
|
|
const multipartFile = {
|
|
name: 'knowledge.pdf',
|
|
size: 1024,
|
|
arrayBuffer: async () => new ArrayBuffer(0),
|
|
} as unknown as FormDataEntryValue
|
|
|
|
expect(isWebFileLike(multipartFile)).toBe(true)
|
|
} finally {
|
|
Object.defineProperty(globalThis, 'File', { configurable: true, value: originalFile })
|
|
}
|
|
})
|
|
|
|
it.each([
|
|
null,
|
|
'knowledge.pdf',
|
|
{ name: 'knowledge.pdf', size: 1024 },
|
|
{ name: 'knowledge.pdf', arrayBuffer: async () => new ArrayBuffer(0) },
|
|
{ size: 1024, arrayBuffer: async () => new ArrayBuffer(0) },
|
|
])('rejects non-file multipart values', (value) => {
|
|
expect(isWebFileLike(value as FormDataEntryValue | null)).toBe(false)
|
|
})
|
|
})
|