Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/__tests__/wait-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ test('does not work after it resolves', async () => {
return undefined
}
},
asyncWrapper: async callback => {
waitForWrapper: async callback => {
contextStack.push('no-act:start')
try {
await callback()
Expand Down
11 changes: 10 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ let config: InternalConfig = {
// so we have this config option that's really only intended for
// react-testing-library to use. For that reason, this feature will remain
// undocumented.
asyncWrapper: cb => cb(),
// Turns out other libraries did use that (user-event).
// Not actually used by DTL but rather by user-event which uses act() from RTL
/* istanbul ignore next */
asyncWrapper: /* istanbul ignore next */ cb =>
/* istanbul ignore next */ cb(),
// For compat with libraries that used asyncWrapper, we add a more specific
// "waitForWrapper" that makes it more clear that this is only meant for waitFor.
// RTL will use this instead to disable act() during that scope while user-event
// can keep relying on the semantics for asyncWrapper.
waitForWrapper: cb => cb(),
unstable_advanceTimersWrapper: cb => cb(),
eventWrapper: cb => cb(),
// default value for the `hidden` option in `ByRole` queries
Expand Down
4 changes: 2 additions & 2 deletions src/wait-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ function waitForWrapper(callback, options) {
// create the error here so its stack trace is as close to the
// calling code as possible
const stackTraceError = new Error('STACK_TRACE_MESSAGE')
return getConfig().asyncWrapper(() =>
waitFor(callback, {stackTraceError, ...options}),
return getConfig().waitForWrapper(
waitFor.bind(null, callback, {stackTraceError, ...options}),
)
}

Expand Down
2 changes: 2 additions & 0 deletions types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface Config {
asyncWrapper(cb: (...args: any[]) => any): Promise<any>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
eventWrapper(cb: (...args: any[]) => any): void
// eslint-disable-next-line @typescript-eslint/no-explicit-any
waitForWrapper(cb: (...args: any[]) => any): Promise<any>
asyncUtilTimeout: number
computedStyleSupportsPseudoElements: boolean
defaultHidden: boolean
Expand Down