Skip to content
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

Experimental test helper: it.experimental #17149

Merged
merged 1 commit into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/react-dom/src/__tests__/ReactUpdates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -1368,8 +1369,8 @@ describe('ReactUpdates', () => {
expect(Scheduler).toFlushAndYield(['Bar']);
}
expect(hiddenDiv.innerHTML).toBe('<p>bar 1</p>');
});
}
},
);

it('can render ridiculously large number of roots without triggering infinite update loop error', () => {
class Foo extends React.Component {
Expand Down
53 changes: 53 additions & 0 deletions scripts/jest/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}