Test should be agnostic of where resolving happens

That's an implementation detail and we might want to change it later. Let's keep it easy by making tests just check that validation happened, not at which stage.
This commit is contained in:
Dan Abramov
2018-11-28 17:25:31 +00:00
parent 41367d334a
commit cf68b96413
2 changed files with 16 additions and 26 deletions
@@ -619,12 +619,12 @@ describe('ReactLazy', () => {
expect(root).toMatchRenderedOutput('22');
// Update
root.update(
<Suspense fallback={<Text text="Loading..." />}>
<LazyAdd inner={false} outer={false} />
</Suspense>,
);
expect(() => {
root.update(
<Suspense fallback={<Text text="Loading..." />}>
<LazyAdd inner={false} outer={false} />
</Suspense>,
);
root.unstable_flushAll();
}).toWarnDev(
'Invalid prop `inner` of type `boolean` supplied to `Add`, expected `number`.',
@@ -804,12 +804,12 @@ describe('ReactLazy', () => {
expect(root).toMatchRenderedOutput('Inner default text');
// Update
root.update(
<Suspense fallback={<Text text="Loading..." />}>
<LazyText text={null} />
</Suspense>,
);
expect(() => {
root.update(
<Suspense fallback={<Text text="Loading..." />}>
<LazyText text={null} />
</Suspense>,
);
root.unstable_flushAll();
}).toWarnDev(
'The prop `text` is marked as required in `T`, but its value is `null`',
@@ -332,16 +332,16 @@ describe('memo', () => {
const Fn = React.memo(FnInner);
// Mount
ReactNoop.render(<Fn inner="2" />);
expect(() => {
ReactNoop.render(<Fn inner="2" />);
ReactNoop.flush();
}).toWarnDev(
'Invalid prop `inner` of type `string` supplied to `FnInner`, expected `number`.',
);
// Update
ReactNoop.render(<Fn inner={false} />);
expect(() => {
ReactNoop.render(<Fn inner={false} />);
ReactNoop.flush();
}).toWarnDev(
'Invalid prop `inner` of type `boolean` supplied to `FnInner`, expected `number`.',
@@ -358,20 +358,20 @@ describe('memo', () => {
// Mount
expect(() => {
ReactNoop.render(<Fn outer="3" />);
ReactNoop.flush();
}).toWarnDev(
// Outer props are checked in createElement
'Invalid prop `outer` of type `string` supplied to `FnInner`, expected `number`.',
);
ReactNoop.flush();
// Update
expect(() => {
ReactNoop.render(<Fn outer={false} />);
ReactNoop.flush();
}).toWarnDev(
// Outer props are checked in createElement
'Invalid prop `outer` of type `boolean` supplied to `FnInner`, expected `number`.',
);
ReactNoop.flush();
});
it('validates nested propTypes declarations', () => {
@@ -394,14 +394,9 @@ describe('memo', () => {
// Mount
expect(() => {
ReactNoop.render(<Outer inner="2" middle="3" outer="4" />);
}).toWarnDev(
// Outer props are checked in createElement
'Invalid prop `outer` of type `string` supplied to `Inner`, expected `number`.',
);
expect(() => {
ReactNoop.flush();
}).toWarnDev([
// There are no actual elements created for these, so they're checked in reconciler.
'Invalid prop `outer` of type `string` supplied to `Inner`, expected `number`.',
'Invalid prop `middle` of type `string` supplied to `Inner`, expected `number`.',
'Invalid prop `inner` of type `string` supplied to `Inner`, expected `number`.',
]);
@@ -411,14 +406,9 @@ describe('memo', () => {
ReactNoop.render(
<Outer inner={false} middle={false} outer={false} />,
);
}).toWarnDev(
// Outer props are checked in createElement
'Invalid prop `outer` of type `boolean` supplied to `Inner`, expected `number`.',
);
expect(() => {
ReactNoop.flush();
}).toWarnDev([
// There are no actual elements created for these, so they're checked in reconciler.
'Invalid prop `outer` of type `boolean` supplied to `Inner`, expected `number`.',
'Invalid prop `middle` of type `boolean` supplied to `Inner`, expected `number`.',
'Invalid prop `inner` of type `boolean` supplied to `Inner`, expected `number`.',
]);