Skip to content

Instantly share code, notes, and snippets.

@vinnymac
Created February 1, 2023 03:21
Show Gist options
  • Save vinnymac/00878aaa1646f08b8c9d06ef21defc34 to your computer and use it in GitHub Desktop.
Save vinnymac/00878aaa1646f08b8c9d06ef21defc34 to your computer and use it in GitHub Desktop.
React 18 Act Environment
function getGlobalThis() {
return global || globalThis || self || window;
}
export function disableReactActEnv() {
let prev: boolean;
beforeEach(() => {
prev = getGlobalThis().IS_REACT_ACT_ENVIRONMENT;
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = false;
});
afterEach(() => {
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = prev;
});
}
export function enableReactActEnv() {
let prev: boolean;
beforeEach(() => {
prev = getGlobalThis().IS_REACT_ACT_ENVIRONMENT;
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = true;
});
afterEach(() => {
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = prev;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment