Skip to content

Commit f9fc440

Browse files
tobilenokonet
authored andcommitted
tests: Upgrade to react 16 / enzyme 3 (react-dropzone#645)
1 parent 25852bb commit f9fc440

File tree

6 files changed

+1026
-549
lines changed

6 files changed

+1026
-549
lines changed

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,37 @@ See https://react-dropzone.netlify.com/#proptypes
9292

9393
*Important*: `react-dropzone` doesn't manage dropped files. You need to destroy the object URL yourself whenever you don't need the `preview` by calling `window.URL.revokeObjectURL(file.preview);` to avoid memory leaks.
9494

95+
### Testing
96+
97+
*Important*: `react-dropzone` makes its drag'n'drop callbacks asynchronous to enable promise based getDataTransfer functions. In order to properly test this, you may want to utilize a helper function to run all promises like this:
98+
```js
99+
const flushPromises = () => new Promise(resolve => setImmediate(resolve));
100+
```
101+
102+
Example with enzyme 3:
103+
```js
104+
105+
it('tests drag state', async () => {
106+
const flushPromises = () => new Promise(resolve => setImmediate(resolve));
107+
const DummyChildComponent = () => null
108+
const dropzone = mount(
109+
<Dropzone>{props => <DummyChildComponent {...props} />}</Dropzone>
110+
)
111+
dropzone.simulate('dragEnter', {
112+
dataTransfer: { files: files.concat(images) }
113+
})
114+
await flushPromises(dropzone)
115+
dropzone.update()
116+
117+
const child = updatedDropzone.find(DummyChildComponent)
118+
expect(child).toHaveProp('isDragActive', true)
119+
expect(child).toHaveProp('isDragAccept', false)
120+
expect(child).toHaveProp('isDragReject', true)
121+
})
122+
```
123+
124+
Remember to update your mounted component before asserting any props. A complete example for this can be found in `react-dropzone`s own test suite.
125+
95126
## Support
96127

97128
### Backers

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
},
7676
"dependencies": {
7777
"attr-accept": "^1.1.3",
78-
"prop-types": "^15.5.7"
78+
"prop-types": "^15.6.2"
7979
},
8080
"devDependencies": {
8181
"@commitlint/cli": "^3.2.0",
@@ -94,7 +94,8 @@
9494
"babel-register": "^6.9.0",
9595
"commitizen": "^2.9.6",
9696
"cross-env": "^5.1.3",
97-
"enzyme": "^2.6.0",
97+
"enzyme": "^3.4.4",
98+
"enzyme-adapter-react-16": "^1.2.0",
9899
"eslint": "^4.6.1",
99100
"eslint-config-okonet": "^5.0.1",
100101
"eslint-config-prettier": "^2.4.0",
@@ -103,14 +104,14 @@
103104
"imagemin-cli": "^3.0.0",
104105
"imagemin-pngquant": "^5.0.0",
105106
"jest": "^21.0.1",
106-
"jest-enzyme": "^3.8.2",
107+
"jest-enzyme": "^6.0.3",
107108
"lint-staged": "^4.1.0",
108109
"markdownlint-cli": "^0.3.1",
109110
"prettier": "^1.6.1",
110-
"react": "^15.4.1",
111-
"react-dom": "^15.4.1",
111+
"react": "^16.4.2",
112+
"react-dom": "^16.4.2",
112113
"react-styleguidist": "^7.2.3",
113-
"react-test-renderer": "^15.6.1",
114+
"react-test-renderer": "^16.4.2",
114115
"rimraf": "^2.5.2",
115116
"rollup": "^0.58.2",
116117
"rollup-plugin-babel": "^3.0.4",

src/__snapshots__/index.spec.js.snap

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
2-
3-
exports[`Dropzone basics should render children 1`] = `"<div class=\\"\\" aria-disabled=\\"false\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\"><p>some content</p><input type=\\"file\\" multiple=\\"\\" autocomplete=\\"off\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\"></div>"`;
4-
5-
exports[`Dropzone document drop protection does not prevent stray drops when preventDropOnDocument is false 1`] = `"<div class=\\"\\" aria-disabled=\\"false\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\"><input type=\\"file\\" multiple=\\"\\" autocomplete=\\"off\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\"></div>"`;
6-
7-
exports[`Dropzone document drop protection installs hooks to prevent stray drops from taking over the browser window 1`] = `"<div class=\\"\\" aria-disabled=\\"false\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\"><p>Content</p><input type=\\"file\\" multiple=\\"\\" autocomplete=\\"off\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\"></div>"`;
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Dropzone basics should render children 1`] = `"<div class=\\"\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\" aria-disabled=\\"false\\"><p>some content</p><input type=\\"file\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\" multiple=\\"\\" autocomplete=\\"off\\"></div>"`;
4+
5+
exports[`Dropzone document drop protection does not prevent stray drops when preventDropOnDocument is false 1`] = `"<div class=\\"\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\" aria-disabled=\\"false\\"><input type=\\"file\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\" multiple=\\"\\" autocomplete=\\"off\\"></div>"`;
6+
7+
exports[`Dropzone document drop protection installs hooks to prevent stray drops from taking over the browser window 1`] = `"<div class=\\"\\" style=\\"position: relative; width: 200px; height: 200px; border-width: 2px; border-color: #666; border-style: dashed; border-radius: 5px;\\" aria-disabled=\\"false\\"><p>Content</p><input type=\\"file\\" style=\\"position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.00001; pointer-events: none;\\" multiple=\\"\\" autocomplete=\\"off\\"></div>"`;

0 commit comments

Comments
 (0)