uppy/packages/@uppy/react/src/useUppyEvent.test.ts
Prakash d301c01d6a
@uppy/utils: update export maps (#5900)
- cleanup `@uppy/utils ` removed unused / redundant modules .
- migrated modules and tests from `.js` to `.ts`
- removed all the nested export paths
- updated `@uppy/utils` import paths for all packages
- `@uppy/angular` is still failing while running`yarn build` , I'm
looking into it.

---------

Co-authored-by: Merlijn Vos <merlijn@soverin.net>
2025-08-19 12:25:27 +02:00

35 lines
1.2 KiB
TypeScript

import { act, renderHook } from '@testing-library/react'
import Uppy from '@uppy/core'
import type { Meta, UppyFile } from '@uppy/utils'
import { describe, expect, expectTypeOf, it, vi } from 'vitest'
import { useUppyEvent } from './index.js'
describe('useUppyEvent', () => {
it('should return and update value with the correct type', () => {
const uppy = new Uppy()
const callback = vi.fn()
const { result, rerender } = renderHook(() =>
useUppyEvent(uppy, 'file-added', callback),
)
act(() =>
uppy.addFile({
source: 'vitest',
name: 'foo1.jpg',
type: 'image/jpeg',
data: new File(['foo1'], 'foo1.jpg', { type: 'image/jpeg' }),
}),
)
expectTypeOf(result.current).toEqualTypeOf<
[[file: UppyFile<Meta, Record<string, never>>] | [], () => void]
>()
expect(result.current[0][0]!.name).toBe('foo1.jpg')
rerender()
expect(result.current[0][0]!.name).toBe('foo1.jpg')
act(() => result.current[1]())
expectTypeOf(result.current).toEqualTypeOf<
[[file: UppyFile<Meta, Record<string, never>>] | [], () => void]
>()
expect(result.current[0]).toStrictEqual([])
expect(callback).toHaveBeenCalledTimes(1)
})
})