-
Notifications
You must be signed in to change notification settings - Fork 470
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,28 @@ function initialCheck(elements) { | |
} | ||
} | ||
|
||
function wrapFunctionCallback(callback) { | ||
return () => { | ||
try { | ||
return callback() | ||
} catch (error) { | ||
if (error.name === 'TestingLibraryElementError') { | ||
return null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original code return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous return value of a similar code pattern was The function Another discussion point is that maybe trying to accept both |
||
} | ||
throw error | ||
} | ||
} | ||
} | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This use of |
||
if (typeof callback === 'function') { | ||
callback = wrapFunctionCallback(callback) | ||
} else { | ||
const elements = Array.isArray(callback) ? callback : [callback] | ||
const getRemainingElements = elements.map(element => { | ||
if (!element) return () => null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line replaces the removed call to |
||
let parent = element.parentElement | ||
if (parent === null) return () => null | ||
while (parent.parentElement) parent = parent.parentElement | ||
|
@@ -30,15 +45,7 @@ async function waitForElementToBeRemoved(callback, options) { | |
initialCheck(callback()) | ||
|
||
return waitFor(() => { | ||
let result | ||
try { | ||
result = callback() | ||
} catch (error) { | ||
if (error.name === 'TestingLibraryElementError') { | ||
return undefined | ||
} | ||
throw error | ||
} | ||
const result = callback() | ||
if (!isRemoved(result)) { | ||
throw timeoutError | ||
} | ||
|
There was a problem hiding this comment.
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.