Skip to content

Commit

Permalink
fix: unofficially support node 6 (#151)
Browse files Browse the repository at this point in the history
<!--
Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated!

Please make sure that you are familiar with and follow the Code of Conduct for
this project (found in the CODE_OF_CONDUCT.md file).

Also, please make sure you're familiar with and follow the instructions in the
contributing guidelines (found in the CONTRIBUTING.md file).

If you're new to contributing to open source projects, you might find this free
video course helpful: http://kcd.im/pull-request

Please fill out the information below to expedite the review and (hopefully)
merge of your pull request!
-->

<!-- What changes are being made? (What feature/bug is being fixed here?) -->

**What**:

*Unofficially* support node 6 by changing `Object.entries` to `Object.keys`

<!-- Why are these changes necessary? -->

**Why**:

I opened a [PR](jestjs/jest#7346) to jest that adds an example for testing with `react-testing-library`.

jest runs it's test suite against node 6 (including the example I added), which is failing because of the call to `Object.entries`.

Switching to `Object.keys` should make the test pass so the PR can be merged 馃樃 

See tweet from @kentcdodds: https://twitter.com/kentcdodds/status/1060735136172466176

<!-- How were these changes implemented? -->

**How**:

With code 馃樃 

<!-- Have you done all of these things?  -->

**Checklist**:

<!-- add "N/A" to the end of each line that's irrelevant to your changes -->

<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->

- [ ] Documentation N/A
- [ ] Tests N/A (I ran them... although not in node 6 馃槄 because the tests use `async`)
- [x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
- [x] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions -->

<!-- feel free to add additional comments -->
  • Loading branch information
terrencewwong authored and Kent C. Dodds committed Nov 9, 2018
1 parent f427ec3 commit eb48038
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Expand Up @@ -401,6 +401,15 @@
"contributions": [
"doc"
]
},
{
"login": "terrencewwong",
"name": "Terrence Wong",
"avatar_url": "https://avatars3.githubusercontent.com/u/5312329?v=4",
"profile": "http://terrencewwong.com",
"contributions": [
"code"
]
}
]
}
28 changes: 14 additions & 14 deletions .size-snapshot.json
@@ -1,30 +1,30 @@
{
"dist/dom-testing-library.cjs.js": {
"bundled": 137666,
"minified": 59811,
"gzipped": 16554
"bundled": 137646,
"minified": 59799,
"gzipped": 16547
},
"dist/dom-testing-library.umd.min.js": {
"bundled": 146462,
"minified": 53705,
"gzipped": 15876
"bundled": 146438,
"minified": 53692,
"gzipped": 15877
},
"dist/dom-testing-library.umd.js": {
"bundled": 146462,
"minified": 53705,
"gzipped": 15876
"bundled": 146438,
"minified": 53692,
"gzipped": 15877
},
"dist/dom-testing-library.esm.js": {
"bundled": 136297,
"minified": 58558,
"gzipped": 16321,
"bundled": 136277,
"minified": 58546,
"gzipped": 16314,
"treeshaked": {
"rollup": {
"code": 41502,
"code": 41487,
"import_statements": 0
},
"webpack": {
"code": 44070
"code": 44061
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -16,7 +16,7 @@
[![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]

[![All Contributors](https://img.shields.io/badge/all_contributors-40-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-41-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Code of Conduct][coc-badge]][coc]

Expand Down Expand Up @@ -92,6 +92,7 @@ when a real user uses it.
- [`fireEvent`](#fireevent)
- [`getNodeText`](#getnodetext)
- [Custom Jest Matchers](#custom-jest-matchers)
- [Custom Queries](#custom-queries)
- [Using other assertion libraries](#using-other-assertion-libraries)
- [`TextMatch`](#textmatch)
- [Precision](#precision)
Expand Down Expand Up @@ -1105,7 +1106,8 @@ Thanks goes to these people ([emoji key][emojis]):
| [<img src="https://avatars3.githubusercontent.com/u/725236?v=4" width="100px;"/><br /><sub><b>Alex Cook</b></sub>](https://github.com/alecook)<br />[馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=alecook "Documentation") [馃挕](#example-alecook "Examples") | [<img src="https://avatars3.githubusercontent.com/u/10348212?v=4" width="100px;"/><br /><sub><b>Daniel Cook</b></sub>](https://github.com/dfcook)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Code") [馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Documentation") [鈿狅笍](https://github.com/kentcdodds/dom-testing-library/commits?author=dfcook "Tests") | [<img src="https://avatars2.githubusercontent.com/u/21194045?s=400&v=4" width="100px;"/><br /><sub><b>Thomas Chia</b></sub>](https://github.com/thchia)<br />[馃悰](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Athchia "Bug reports") [馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=thchia "Code") | [<img src="https://avatars1.githubusercontent.com/u/28659384?v=4" width="100px;"/><br /><sub><b>Tim Deschryver</b></sub>](https://github.com/tdeschryver)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Code") [鈿狅笍](https://github.com/kentcdodds/dom-testing-library/commits?author=tdeschryver "Tests") | [<img src="https://avatars3.githubusercontent.com/u/1571667?v=4" width="100px;"/><br /><sub><b>Alex Krolick</b></sub>](https://alexkrolick.com)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=alexkrolick "Code") | [<img src="https://avatars2.githubusercontent.com/u/2224291?v=4" width="100px;"/><br /><sub><b>Maddi Joyce</b></sub>](http://www.maddijoyce.com)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=maddijoyce "Code") | [<img src="https://avatars1.githubusercontent.com/u/25429764?v=4" width="100px;"/><br /><sub><b>Peter Kamps</b></sub>](https://github.com/npeterkamps)<br />[馃悰](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Anpeterkamps "Bug reports") [馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=npeterkamps "Code") [鈿狅笍](https://github.com/kentcdodds/dom-testing-library/commits?author=npeterkamps "Tests") |
| [<img src="https://avatars2.githubusercontent.com/u/21689428?v=4" width="100px;"/><br /><sub><b>Jonathan Stoye</b></sub>](http://jonathanstoye.de)<br />[馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=JonathanStoye "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/4126644?v=4" width="100px;"/><br /><sub><b>Sanghyeon Lee</b></sub>](https://github.com/yongdamsh)<br />[馃挕](#example-yongdamsh "Examples") | [<img src="https://avatars3.githubusercontent.com/u/8015514?v=4" width="100px;"/><br /><sub><b>Justice Mba </b></sub>](https://github.com/Dajust)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=Dajust "Code") [馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=Dajust "Documentation") [馃](#ideas-Dajust "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/340761?v=4" width="100px;"/><br /><sub><b>Wayne Crouch</b></sub>](https://github.com/wgcrouch)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=wgcrouch "Code") | [<img src="https://avatars1.githubusercontent.com/u/4996462?v=4" width="100px;"/><br /><sub><b>Ben Elliott</b></sub>](http://benjaminelliott.co.uk)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=benelliott "Code") | [<img src="https://avatars3.githubusercontent.com/u/577921?v=4" width="100px;"/><br /><sub><b>Ruben Costa</b></sub>](http://nuances.co)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=rubencosta "Code") | [<img src="https://avatars2.githubusercontent.com/u/4982001?v=4" width="100px;"/><br /><sub><b>Robert Smith</b></sub>](http://rbrtsmith.com/)<br />[馃悰](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Arbrtsmith "Bug reports") [馃](#ideas-rbrtsmith "Ideas, Planning, & Feedback") [馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=rbrtsmith "Documentation") |
| [<img src="https://avatars3.githubusercontent.com/u/881986?v=4" width="100px;"/><br /><sub><b>dadamssg</b></sub>](https://github.com/dadamssg)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=dadamssg "Code") | [<img src="https://avatars1.githubusercontent.com/u/186971?v=4" width="100px;"/><br /><sub><b>Neil Kistner</b></sub>](https://neilkistner.com/)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=wyze "Code") | [<img src="https://avatars3.githubusercontent.com/u/1448597?v=4" width="100px;"/><br /><sub><b>Ben Chauvette</b></sub>](http://bdchauvette.net/)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=bdchauvette "Code") | [<img src="https://avatars2.githubusercontent.com/u/777527?v=4" width="100px;"/><br /><sub><b>Jeff Baumgardt</b></sub>](https://github.com/JeffBaumgardt)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=JeffBaumgardt "Code") [馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=JeffBaumgardt "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/4658208?v=4" width="100px;"/><br /><sub><b>Matan Kushner</b></sub>](http://matchai.me)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Code") [馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Documentation") [馃](#ideas-matchai "Ideas, Planning, & Feedback") [鈿狅笍](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Tests") | [<img src="https://avatars2.githubusercontent.com/u/5779538?v=4" width="100px;"/><br /><sub><b>Alex Wendte</b></sub>](http://www.wendtedesigns.com/)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Code") [馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Documentation") [鈿狅笍](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Tests") | [<img src="https://avatars0.githubusercontent.com/u/2196208?v=4" width="100px;"/><br /><sub><b>Tamas Fodor</b></sub>](https://github.com/ruffle1986)<br />[馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=ruffle1986 "Documentation") |
| [<img src="https://avatars3.githubusercontent.com/u/14793495?v=4" width="100px;"/><br /><sub><b>Benjamin Eckardt</b></sub>](https://github.com/BenjaminEckardt)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=BenjaminEckardt "Code") | [<img src="https://avatars3.githubusercontent.com/u/205752?v=4" width="100px;"/><br /><sub><b>Ryan Campbell</b></sub>](https://github.com/campbellr)<br />[馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=campbellr "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/1335519?v=4" width="100px;"/><br /><sub><b>Taylor Briggs</b></sub>](https://taylor-briggs.com)<br />[鈿狅笍](https://github.com/kentcdodds/dom-testing-library/commits?author=TaylorBriggs "Tests") | [<img src="https://avatars2.githubusercontent.com/u/132233?v=4" width="100px;"/><br /><sub><b>John Gozde</b></sub>](https://github.com/jgoz)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=jgoz "Code") | [<img src="https://avatars2.githubusercontent.com/u/3382565?v=4" width="100px;"/><br /><sub><b>C. T. Lin</b></sub>](https://github.com/chentsulin)<br />[馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=chentsulin "Documentation") |
| [<img src="https://avatars3.githubusercontent.com/u/14793495?v=4" width="100px;"/><br /><sub><b>Benjamin Eckardt</b></sub>](https://github.com/BenjaminEckardt)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=BenjaminEckardt "Code") | [<img src="https://avatars3.githubusercontent.com/u/205752?v=4" width="100px;"/><br /><sub><b>Ryan Campbell</b></sub>](https://github.com/campbellr)<br />[馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=campbellr "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/1335519?v=4" width="100px;"/><br /><sub><b>Taylor Briggs</b></sub>](https://taylor-briggs.com)<br />[鈿狅笍](https://github.com/kentcdodds/dom-testing-library/commits?author=TaylorBriggs "Tests") | [<img src="https://avatars2.githubusercontent.com/u/132233?v=4" width="100px;"/><br /><sub><b>John Gozde</b></sub>](https://github.com/jgoz)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=jgoz "Code") | [<img src="https://avatars2.githubusercontent.com/u/3382565?v=4" width="100px;"/><br /><sub><b>C. T. Lin</b></sub>](https://github.com/chentsulin)<br />[馃摉](https://github.com/kentcdodds/dom-testing-library/commits?author=chentsulin "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/5312329?v=4" width="100px;"/><br /><sub><b>Terrence Wong</b></sub>](http://terrencewwong.com)<br />[馃捇](https://github.com/kentcdodds/dom-testing-library/commits?author=terrencewwong "Code") |

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors][all-contributors] specification.
Expand Down
6 changes: 4 additions & 2 deletions src/events.js
Expand Up @@ -299,7 +299,8 @@ function fireEvent(element, event) {
return element.dispatchEvent(event)
}

Object.entries(eventMap).forEach(([key, {EventType, defaultInit}]) => {
Object.keys(eventMap).forEach(key => {
const {EventType, defaultInit} = eventMap[key]
const eventName = key.toLowerCase()

fireEvent[key] = (node, init) => {
Expand Down Expand Up @@ -344,7 +345,8 @@ function setNativeValue(element, value) {
}
}

Object.entries(eventAliasMap).forEach(([aliasKey, key]) => {
Object.keys(eventAliasMap).forEach(aliasKey => {
const key = eventAliasMap[aliasKey]
fireEvent[aliasKey] = (...args) => fireEvent[key](...args)
})

Expand Down
3 changes: 2 additions & 1 deletion src/get-queries-for-element.js
Expand Up @@ -10,7 +10,8 @@ import * as defaultQueries from './queries'
* @returns {FuncMap} returns object of functions bound to container
*/
function getQueriesForElement(element, queries = defaultQueries) {
return Object.entries(queries).reduce((helpers, [key, fn]) => {
return Object.keys(queries).reduce((helpers, key) => {
const fn = queries[key]
helpers[key] = fn.bind(null, element)
return helpers
}, {})
Expand Down

0 comments on commit eb48038

Please sign in to comment.