Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(waitForElementToBeRemoved): Make initial check work with getBy*. #1094

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

make-github-pseudonymous-again

This commit includes a regression test. Fixes #1093.

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d5b3f35:

Sandbox Source
react-testing-library-examples Configuration

async function waitForElementToBeRemoved(callback, options) {
// created here so we get a nice stacktrace
const timeoutError = new Error('Timed out in waitForElementToBeRemoved.')
if (typeof callback !== 'function') {
initialCheck(callback)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This use of initialCheck is replaced by a simpler check.

const elements = Array.isArray(callback) ? callback : [callback]
const getRemainingElements = elements.map(element => {
if (!element) return () => null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line replaces the removed call to initialCheck.

@codecov
Copy link

codecov bot commented Jan 25, 2022

Codecov Report

Merging #1094 (d5b3f35) into main (d578c7e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #1094   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines          954       959    +5     
  Branches       314       316    +2     
=========================================
+ Hits           954       959    +5     
Flag Coverage Δ
node-12 100.00% <100.00%> (ø)
node-14 100.00% <100.00%> (ø)
node-16.9.1 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/wait-for-element-to-be-removed.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d578c7e...d5b3f35. Read the comment docs.

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It does look like the new behavior is intended.

Though the implementation needs some work.

@@ -12,13 +12,28 @@ function initialCheck(elements) {
}
}

function wrapFunctionCallback(callback) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"wrap" it with what? It would help a lot if we could come up with a less generic name for this function.

return callback()
} catch (error) {
if (error.name === 'TestingLibraryElementError') {
return null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code return undefined. Is there a reason to change the return type now?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous return value of a similar code pattern was undefined because it was directly mapping to the return value needed by the waitFor callback. Now the code is almost the same but null gets translated to undefined through some indirection: isRemoved(null) yields undefined.

The function wrapFunctionCallback is currently defined as a convenience transformation of getBy* queries to make them behave like queryBy* queries. Maybe this help answer #1094 (comment)?

Another discussion point is that maybe trying to accept both getBy*- and queryBy*-based callbacks is a mistake. The way it is implemented now, we could remove wrapFunctionCallback if the user only used queryBy*-based callbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Behavior of waitForElementToBeRemoved when first call throws
2 participants