Skip to content

Commit 3766812

Browse files
author
Sunil Pai
committed
pass lint/flow checks (without requiring a Promise polyfill/exclusion)
1 parent d36b8d5 commit 3766812

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

packages/react-dom/src/test-utils/ReactTestUtils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,19 @@ try {
181181
};
182182
}
183183

184+
let globalPromise = null;
185+
if (typeof window !== 'undefined') {
186+
globalPromise = window.Promise;
187+
} else if (typeof global !== 'undefined') {
188+
globalPromise = global.Promise;
189+
}
190+
184191
function runCallbackUntilPredicateFails(
185192
callback: () => void,
186193
predicate: () => boolean,
187194
) {
188-
// eslint-disable-next-line no-undef
189-
return new Promise((resolve, reject) => {
195+
// $FlowFixMe - if we've reached this far, we're certain Promise is available
196+
return new globalPromise((resolve, reject) => {
190197
callback();
191198
enqueueTask(() => {
192199
if (predicate()) {

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,12 +996,19 @@ try {
996996
};
997997
}
998998

999+
let globalPromise = null;
1000+
if (typeof window !== 'undefined') {
1001+
globalPromise = window.Promise;
1002+
} else if (typeof global !== 'undefined') {
1003+
globalPromise = global.Promise;
1004+
}
1005+
9991006
function runCallbackUntilPredicateFails(
10001007
callback: () => void,
10011008
predicate: () => boolean,
10021009
) {
1003-
// eslint-disable-next-line no-undef
1004-
return new Promise((resolve, reject) => {
1010+
// $FlowFixMe - if we've reached this far, we're certain Promise is available
1011+
return new globalPromise((resolve, reject) => {
10051012
callback();
10061013
enqueueTask(() => {
10071014
if (predicate()) {

packages/react-test-renderer/src/ReactTestRenderer.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,19 @@ try {
628628
};
629629
}
630630

631+
let globalPromise = null;
632+
if (typeof window !== 'undefined') {
633+
globalPromise = window.Promise;
634+
} else if (typeof global !== 'undefined') {
635+
globalPromise = global.Promise;
636+
}
637+
631638
function runCallbackUntilPredicateFails(
632639
callback: () => void,
633640
predicate: () => boolean,
634641
) {
635-
// eslint-disable-next-line no-undef
636-
return new Promise((resolve, reject) => {
642+
// $FlowFixMe - if we've reached this far, we're certain Promise is available
643+
return new globalPromise((resolve, reject) => {
637644
callback();
638645
enqueueTask(() => {
639646
if (predicate()) {

0 commit comments

Comments
 (0)