-
Notifications
You must be signed in to change notification settings - Fork 274
fix: force cast await to proper type #1293
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
Changes from all commits
8d71c73
b4a6d21
f2e267c
76df44c
a6498df
90624af
2e375eb
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 |
---|---|---|
|
@@ -3,9 +3,7 @@ | |
import { act as reactTestRendererAct } from 'react-test-renderer'; | ||
import { checkReactVersionAtLeast } from './react-versions'; | ||
|
||
const actMock = (callback: () => void) => { | ||
callback(); | ||
}; | ||
type ReactAct = typeof reactTestRendererAct; | ||
|
||
// See https://github.com/reactwg/react-18/discussions/102 for more context on global.IS_REACT_ACT_ENVIRONMENT | ||
declare global { | ||
|
@@ -20,10 +18,8 @@ function getIsReactActEnvironment() { | |
return globalThis.IS_REACT_ACT_ENVIRONMENT; | ||
} | ||
|
||
type Act = typeof reactTestRendererAct; | ||
|
||
function withGlobalActEnvironment(actImplementation: Act) { | ||
return (callback: Parameters<Act>[0]) => { | ||
function withGlobalActEnvironment(actImplementation: ReactAct) { | ||
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. Is it even useful to pass it 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. hmmmm, good question, we've got our code from RTL and just sprinkled types and eslint ignores over it. |
||
return (callback: Parameters<ReactAct>[0]) => { | ||
const previousActEnvironment = getIsReactActEnvironment(); | ||
setIsReactActEnvironment(true); | ||
|
||
|
@@ -44,6 +40,7 @@ function withGlobalActEnvironment(actImplementation: Act) { | |
} | ||
return result; | ||
}); | ||
|
||
if (callbackNeedsToBeAwaited) { | ||
const thenable = actResult; | ||
return { | ||
|
@@ -77,16 +74,10 @@ function withGlobalActEnvironment(actImplementation: Act) { | |
} | ||
}; | ||
} | ||
const getAct = () => { | ||
if (!reactTestRendererAct) { | ||
return actMock; | ||
} | ||
|
||
return checkReactVersionAtLeast(18, 0) | ||
? withGlobalActEnvironment(reactTestRendererAct) | ||
: reactTestRendererAct; | ||
}; | ||
const act = getAct(); | ||
const act: ReactAct = checkReactVersionAtLeast(18, 0) | ||
? (withGlobalActEnvironment(reactTestRendererAct) as ReactAct) | ||
: reactTestRendererAct; | ||
|
||
export default act; | ||
export { | ||
|
Uh oh!
There was an error while loading. Please reload this page.