Skip to content

Commit

Permalink
test: expect DataTransfer.types to follow specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-fritsche committed Jan 12, 2025
1 parent dcaaf90 commit 98bc5e0
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions tests/utils/dataTransfer/DataTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { waitFor } from '@testing-library/dom'
import {createDataTransfer, getBlobFromDataTransferItem} from '#src/utils'

describe('create DataTransfer', () => {
Expand All @@ -9,7 +10,7 @@ describe('create DataTransfer', () => {

const callback = mocks.fn()
dt.items[0].getAsString(callback)
expect(callback).toBeCalledWith('foo')
await waitFor(() => expect(callback).toBeCalledWith('foo'))
})

test('multi format', async () => {
Expand All @@ -21,7 +22,6 @@ describe('create DataTransfer', () => {

expect(dt.getData('text/plain')).toBe('foo')
expect(dt.getData('text/html')).toBe('bar')
expect(dt.getData('text/*')).toBe('foo')
expect(dt.getData('text')).toBe('foo')

dt.clearData()
Expand All @@ -45,7 +45,12 @@ describe('create DataTransfer', () => {
const dt = createDataTransfer(window, [f0, f1])
dt.setData('text/html', 'foo')

expect(dt.types).toEqual(['Files', 'text/html'])
expect(dt.types).toEqual(expect.arrayContaining(
// TODO: Fix DataTransferStub
typeof window.DataTransfer === 'undefined'
? ['Files', 'text/html']
: ['text/html']
))
expect(dt.files.length).toBe(2)
})

Expand All @@ -55,7 +60,14 @@ describe('create DataTransfer', () => {
dt.setData('text/html', 'foo')
dt.items.add(f0)

expect(dt.types).toEqual(['text/html', 'text/plain'])
expect(dt.types).toEqual(
expect.arrayContaining(
// TODO: Fix DataTransferStub
typeof window.DataTransfer === 'undefined'
? ['text/html', 'text/plain']
: ['text/html', 'Files'],
),
)

expect(dt.items[0].getAsFile()).toBe(null)
expect(dt.items[1].getAsFile()).toBe(f0)
Expand All @@ -73,15 +85,21 @@ describe('create DataTransfer', () => {

dt.clearData('text/plain')

expect(dt.types).toEqual(['text/html'])

dt.clearData('text/plain')

expect(dt.types).toEqual(['text/html'])

dt.clearData()

expect(dt.types).toEqual([])
expect(dt.types).toEqual(
expect.arrayContaining(
// TODO: Fix DataTransferStub
typeof window.DataTransfer === 'undefined'
? ['text/html']
: ['text/html', 'Files'],
),
)

dt.clearData('text/html')

expect(dt.types).toEqual(
// TODO: Fix DataTransferStub
typeof window.DataTransfer === 'undefined' ? [] : ['Files'],
)
})
})

Expand Down

0 comments on commit 98bc5e0

Please sign in to comment.