Skip to content

Commit

Permalink
chore: update deps and fix the act() test warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandjitsu committed Sep 23, 2020
1 parent 624549c commit aaa9710
Show file tree
Hide file tree
Showing 8 changed files with 21,808 additions and 15,949 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [8, 10, 12, 14]
node_version: [10, 12, 14]

steps:
- uses: actions/checkout@master
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
@@ -0,0 +1 @@
12.18
22 changes: 6 additions & 16 deletions README.md
Expand Up @@ -231,16 +231,11 @@ dropzoneRef.open()

## Testing

*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:
```js static
const flushPromises = () => new Promise(resolve => setImmediate(resolve))
```

Example with [react-testing-library](https://github.com/kentcdodds/react-testing-library):
*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):
```js static
import React from 'react'
import Dropzone from 'react-dropzone'
import { fireEvent, render } from 'react-testing-library'
import { act, fireEvent, render, waitFor } from '@testing-library/react'

test('invoke onDragEnter when dragenter event occurs', async () => {
const file = new File([
Expand All @@ -258,22 +253,17 @@ test('invoke onDragEnter when dragenter event occurs', async () => {
)}
</Dropzone>
)
const { container } = render(ui)
const { container, rerender } = render(ui)
const dropzone = container.querySelector('div')

dispatchEvt(dropzone, 'dragenter', data)
await flushPromises(ui, container)
await flushPromises(rerender, ui)

expect(onDragEnter).toHaveBeenCalled()
})

function flushPromises(ui, container) {
return new Promise(resolve =>
setImmediate(() => {
render(ui, { container })
resolve(container)
})
)
async function flushPromises(rerender, ui) {
await act(() => waitFor(() => rerender(ui)))
}

function dispatchEvt(node, type, data) {
Expand Down

0 comments on commit aaa9710

Please sign in to comment.