Skip to content

Commit aaa9710

Browse files
committed
chore: update deps and fix the act() test warnings
1 parent 624549c commit aaa9710

File tree

8 files changed

+21808
-15949
lines changed

8 files changed

+21808
-15949
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node_version: [8, 10, 12, 14]
14+
node_version: [10, 12, 14]
1515

1616
steps:
1717
- uses: actions/checkout@master

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12.18

README.md

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,11 @@ dropzoneRef.open()
231231

232232
## Testing
233233

234-
*Important*: `react-dropzone` makes some of its drag 'n' drop callbacks asynchronous to enable promise based `getFilesFromEvent()` functions. In order to properly test this, you may want to utilize a helper function to run all promises like this:
235-
```js static
236-
const flushPromises = () => new Promise(resolve => setImmediate(resolve))
237-
```
238-
239-
Example with [react-testing-library](https://github.com/kentcdodds/react-testing-library):
234+
*Important*: `react-dropzone` makes some of its drag 'n' drop callbacks asynchronous to enable promise based `getFilesFromEvent()` functions. In order to test components that use this library, you may want to use the [react-testing-library](https://github.com/testing-library/react-testing-library):
240235
```js static
241236
import React from 'react'
242237
import Dropzone from 'react-dropzone'
243-
import { fireEvent, render } from 'react-testing-library'
238+
import { act, fireEvent, render, waitFor } from '@testing-library/react'
244239

245240
test('invoke onDragEnter when dragenter event occurs', async () => {
246241
const file = new File([
@@ -258,22 +253,17 @@ test('invoke onDragEnter when dragenter event occurs', async () => {
258253
)}
259254
</Dropzone>
260255
)
261-
const { container } = render(ui)
256+
const { container, rerender } = render(ui)
262257
const dropzone = container.querySelector('div')
263258

264259
dispatchEvt(dropzone, 'dragenter', data)
265-
await flushPromises(ui, container)
260+
await flushPromises(rerender, ui)
266261

267262
expect(onDragEnter).toHaveBeenCalled()
268263
})
269264

270-
function flushPromises(ui, container) {
271-
return new Promise(resolve =>
272-
setImmediate(() => {
273-
render(ui, { container })
274-
resolve(container)
275-
})
276-
)
265+
async function flushPromises(rerender, ui) {
266+
await act(() => waitFor(() => rerender(ui)))
277267
}
278268

279269
function dispatchEvt(node, type, data) {

0 commit comments

Comments
 (0)