mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-21 01:15:35 +00:00
@uppy/core: add type tests (#5153)
This commit is contained in:
parent
b7b65b9aeb
commit
28767b4cf4
1 changed files with 51 additions and 0 deletions
51
packages/@uppy/core/src/types.test.ts
Normal file
51
packages/@uppy/core/src/types.test.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { expectTypeOf, test } from 'vitest'
|
||||
|
||||
import type { Body, InternalMetadata, Meta } from '@uppy/utils/lib/UppyFile'
|
||||
import Uppy from './Uppy'
|
||||
import UIPlugin, { type UIPluginOptions } from './UIPlugin'
|
||||
|
||||
interface Opts extends UIPluginOptions {
|
||||
foo: string
|
||||
}
|
||||
class TestPlugin<M extends Meta, B extends Body> extends UIPlugin<Opts, M, B> {
|
||||
constructor(uppy: Uppy<M, B>, opts?: Opts) {
|
||||
super(uppy, opts)
|
||||
this.id = 'TestPlugin'
|
||||
this.type = 'acquirer'
|
||||
}
|
||||
}
|
||||
|
||||
test('can use Uppy class without generics', async () => {
|
||||
const core = new Uppy()
|
||||
expectTypeOf(core).toEqualTypeOf<Uppy<Meta, Body>>()
|
||||
})
|
||||
|
||||
test('can .use() a plugin', async () => {
|
||||
const core = new Uppy().use(TestPlugin)
|
||||
expectTypeOf(core).toEqualTypeOf<Uppy<Meta, Body>>()
|
||||
})
|
||||
|
||||
test('Meta and Body generic move through the Uppy class', async () => {
|
||||
type M = { foo: string }
|
||||
type B = { bar: string }
|
||||
const core = new Uppy<M, B>()
|
||||
|
||||
core.addUploader(() => Promise.resolve())
|
||||
|
||||
core.on('complete', (result) => {
|
||||
expectTypeOf(result.successful?.[0]?.response?.body).toEqualTypeOf<
|
||||
B | undefined
|
||||
>()
|
||||
})
|
||||
|
||||
const id = core.addFile({
|
||||
source: 'vi',
|
||||
name: 'foo.jpg',
|
||||
type: 'image/jpeg',
|
||||
data: new Blob(),
|
||||
})
|
||||
|
||||
expectTypeOf(core.getFile(id).meta).toEqualTypeOf<InternalMetadata & M>()
|
||||
|
||||
await core.upload()
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue