diff --git a/packages/react-dom/src/__tests__/ReactUpdates-test.js b/packages/react-dom/src/__tests__/ReactUpdates-test.js index 04e69d591e17c..cb4d8214c1cbc 100644 --- a/packages/react-dom/src/__tests__/ReactUpdates-test.js +++ b/packages/react-dom/src/__tests__/ReactUpdates-test.js @@ -1292,8 +1292,9 @@ describe('ReactUpdates', () => { expect(ops).toEqual(['Foo', 'Bar', 'Baz']); }); - if (__EXPERIMENTAL__) { - it('delays sync updates inside hidden subtrees in Concurrent Mode', () => { + it.experimental( + 'delays sync updates inside hidden subtrees in Concurrent Mode', + () => { const container = document.createElement('div'); function Baz() { @@ -1368,8 +1369,8 @@ describe('ReactUpdates', () => { expect(Scheduler).toFlushAndYield(['Bar']); } expect(hiddenDiv.innerHTML).toBe('
bar 1
'); - }); - } + }, + ); it('can render ridiculously large number of roots without triggering infinite update loop error', () => { class Foo extends React.Component { diff --git a/scripts/jest/setupTests.js b/scripts/jest/setupTests.js index b2933bc5fba55..330cf65c0fc68 100644 --- a/scripts/jest/setupTests.js +++ b/scripts/jest/setupTests.js @@ -205,5 +205,58 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) { global.Error = ErrorProxy; } + const expectExperimentalToFail = async callback => { + if (callback.length > 0) { + throw Error( + 'Experimental test helpers do not support `done` callback. Return a ' + + 'promise instead.' + ); + } + try { + const maybePromise = callback(); + if ( + maybePromise !== undefined && + maybePromise !== null && + typeof maybePromise.then === 'function' + ) { + await maybePromise; + } + } catch (error) { + // Failed as expected + return; + } + throw Error( + 'Tests marked experimental are expected to fail, but this one passed.' + ); + }; + + const it = global.it; + const fit = global.fit; + const xit = global.xit; + if (__EXPERIMENTAL__) { + it.experimental = it; + fit.experimental = it.only.experimental = it.experimental.only = fit; + xit.experimental = it.skip.experimental = it.experimental.skip = xit; + } else { + it.experimental = (message, callback) => { + it(`[EXPERIMENTAL, SHOULD FAIL] ${message}`, () => + expectExperimentalToFail(callback)); + }; + fit.experimental = it.only.experimental = it.experimental.only = ( + message, + callback + ) => { + fit(`[EXPERIMENTAL, SHOULD FAIL] ${message}`, () => + expectExperimentalToFail(callback)); + }; + xit.experimental = it.skip.experimental = it.experimental.skip = ( + message, + callback + ) => { + xit(`[EXPERIMENTAL, SHOULD FAIL] ${message}`, () => + expectExperimentalToFail(callback)); + }; + } + require('jasmine-check').install(); }