Skip to content

Commit 98bc5e0

Browse files
committed
test: expect DataTransfer.types to follow specs
1 parent dcaaf90 commit 98bc5e0

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

tests/utils/dataTransfer/DataTransfer.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { waitFor } from '@testing-library/dom'
12
import {createDataTransfer, getBlobFromDataTransferItem} from '#src/utils'
23

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

1011
const callback = mocks.fn()
1112
dt.items[0].getAsString(callback)
12-
expect(callback).toBeCalledWith('foo')
13+
await waitFor(() => expect(callback).toBeCalledWith('foo'))
1314
})
1415

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

2223
expect(dt.getData('text/plain')).toBe('foo')
2324
expect(dt.getData('text/html')).toBe('bar')
24-
expect(dt.getData('text/*')).toBe('foo')
2525
expect(dt.getData('text')).toBe('foo')
2626

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

48-
expect(dt.types).toEqual(['Files', 'text/html'])
48+
expect(dt.types).toEqual(expect.arrayContaining(
49+
// TODO: Fix DataTransferStub
50+
typeof window.DataTransfer === 'undefined'
51+
? ['Files', 'text/html']
52+
: ['text/html']
53+
))
4954
expect(dt.files.length).toBe(2)
5055
})
5156

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

58-
expect(dt.types).toEqual(['text/html', 'text/plain'])
63+
expect(dt.types).toEqual(
64+
expect.arrayContaining(
65+
// TODO: Fix DataTransferStub
66+
typeof window.DataTransfer === 'undefined'
67+
? ['text/html', 'text/plain']
68+
: ['text/html', 'Files'],
69+
),
70+
)
5971

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

7486
dt.clearData('text/plain')
7587

76-
expect(dt.types).toEqual(['text/html'])
77-
78-
dt.clearData('text/plain')
79-
80-
expect(dt.types).toEqual(['text/html'])
81-
82-
dt.clearData()
83-
84-
expect(dt.types).toEqual([])
88+
expect(dt.types).toEqual(
89+
expect.arrayContaining(
90+
// TODO: Fix DataTransferStub
91+
typeof window.DataTransfer === 'undefined'
92+
? ['text/html']
93+
: ['text/html', 'Files'],
94+
),
95+
)
96+
97+
dt.clearData('text/html')
98+
99+
expect(dt.types).toEqual(
100+
// TODO: Fix DataTransferStub
101+
typeof window.DataTransfer === 'undefined' ? [] : ['Files'],
102+
)
85103
})
86104
})
87105

0 commit comments

Comments
 (0)