Skip to content

Commit

Permalink
add cypress-testing-library
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed Apr 16, 2018
1 parent b46117c commit edfaa9c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 42 deletions.
42 changes: 0 additions & 42 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
import {generate} from '../utils'
import * as queries from './queries'

Cypress.Commands.add('getByTestId', id => {
return cy.get(`[data-testid="${id}"]`)
})

Cypress.Commands.add('getByLabelText', (...args) => {
return cy
.window()
.then(({document}) =>
getCommandWaiter(document, () =>
queries.queryByLabelText(document, ...args),
)(),
)
})

Cypress.Commands.add('getByText', (...args) => {
return cy
.window()
.then(({document}) =>
getCommandWaiter(document, () =>
queries.queryByText(document, ...args),
)(),
)
})

function getCommandWaiter(container, fn) {
return function waiter() {
const val = fn()
if (val) {
return val
} else {
return new Promise(resolve => {
const observer = new MutationObserver(() => {
observer.disconnect()
resolve(waiter())
})
observer.observe(container, {subtree: true, childList: true})
})
}
}
}

Cypress.Commands.add('logout', () => {
return cy
Expand Down
1 change: 1 addition & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import 'babel-polyfill'
import 'cypress-testing-library/add-commands'
import './commands'
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"cross-env": "^5.1.3",
"cross-spawn": "^6.0.4",
"cypress": "^2.0.2",
"cypress-testing-library": "^1.0.0",
"doctoc": "^1.3.0",
"eslint": "^4.18.0",
"eslint-config-kentcdodds": "^13.0.1",
Expand Down

0 comments on commit edfaa9c

Please sign in to comment.