Skip to content

Commit

Permalink
Use advanceTimersWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Sep 5, 2021
1 parent 9938c9e commit 14d5753
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 312 deletions.
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module.exports = Object.assign(jestConfig, {
// full coverage across the build matrix (React 17, 18) but not in a single job
'./src/pure': {
// minimum coverage of jobs using React 17 and 18
branches: 82,
functions: 76,
lines: 81,
statements: 81,
branches: 80,
functions: 84,
lines: 89,
statements: 89,
},
},
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.12.5",
"@testing-library/dom": "^8.0.0"
"@testing-library/dom": "https://pkg.csb.dev/testing-library/dom-testing-library/commit/9d12234d/@testing-library/dom"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.6",
Expand Down
88 changes: 0 additions & 88 deletions src/dtlHelpers.js

This file was deleted.

23 changes: 10 additions & 13 deletions src/pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {
getQueriesForElement,
prettyDOM,
configure as configureDTL,
waitForElementToBeRemoved as waitForElementToBeRemovedDTL,
} from '@testing-library/dom'
import act from './act-compat'
import {fireEvent} from './fire-event'
import {waitFor} from './wait-for'

configureDTL({
eventWrapper: cb => {
Expand All @@ -20,6 +18,15 @@ configureDTL({
},
})

if (typeof React.startTransition !== undefined) {
configureDTL({
unstable_advanceTimersWrapper: cb => {
return act(cb)
},
asyncWrapper: cb => cb(),
})
}

// Ideally we'd just use a WeakMap where containers are keys and roots are values.
// We use two variables so that we can bail out in constant time when we render with a new container (most common use case)
/**
Expand Down Expand Up @@ -192,19 +199,9 @@ function cleanup() {
mountedContainers.clear()
}

function waitForElementToBeRemoved(callback, options) {
return waitForElementToBeRemovedDTL(() => {
let result
act(() => {
result = callback()
})
return result
}, options)
}

// just re-export everything from dom-testing-library
export * from '@testing-library/dom'
export {render, cleanup, act, fireEvent, waitFor, waitForElementToBeRemoved}
export {render, cleanup, act, fireEvent}

// NOTE: we're not going to export asyncAct because that's our own compatibility
// thing for people using [email protected]. Anyone else doesn't need it and
Expand Down
206 changes: 0 additions & 206 deletions src/wait-for.js

This file was deleted.

0 comments on commit 14d5753

Please sign in to comment.