Skip to content

Commit

Permalink
Rename toLowPriorityWarnDev -> toWarnDev in tests and implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Dec 14, 2019
1 parent aae46f6 commit 35313aa
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 50 deletions.
24 changes: 10 additions & 14 deletions packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ describe('ReactComponentLifeCycle', () => {
expect(() => ReactDOM.render(<Component />, container)).toErrorDev(
'Unsafe legacy lifecycles will not be called for components using new component APIs.',
);
}).toLowPriorityWarnDev(
}).toWarnDev(
[
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
Expand Down Expand Up @@ -735,7 +735,7 @@ describe('ReactComponentLifeCycle', () => {
).toErrorDev(
'Unsafe legacy lifecycles will not be called for components using new component APIs.',
);
}).toLowPriorityWarnDev(
}).toWarnDev(
[
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
Expand Down Expand Up @@ -803,7 +803,7 @@ describe('ReactComponentLifeCycle', () => {
'The above lifecycles should be removed. Learn more about this warning here:\n' +
'https://fb.me/react-unsafe-component-lifecycles',
);
}).toLowPriorityWarnDev(
}).toWarnDev(
[
'componentWillMount has been renamed',
'componentWillUpdate has been renamed',
Expand Down Expand Up @@ -853,7 +853,7 @@ describe('ReactComponentLifeCycle', () => {
'The above lifecycles should be removed. Learn more about this warning here:\n' +
'https://fb.me/react-unsafe-component-lifecycles',
);
}).toLowPriorityWarnDev(['componentWillMount has been renamed'], {
}).toWarnDev(['componentWillMount has been renamed'], {
withoutStack: true,
});

Expand All @@ -876,7 +876,7 @@ describe('ReactComponentLifeCycle', () => {
'The above lifecycles should be removed. Learn more about this warning here:\n' +
'https://fb.me/react-unsafe-component-lifecycles',
);
}).toLowPriorityWarnDev(['componentWillReceiveProps has been renamed'], {
}).toWarnDev(['componentWillReceiveProps has been renamed'], {
withoutStack: true,
});
});
Expand Down Expand Up @@ -908,7 +908,7 @@ describe('ReactComponentLifeCycle', () => {
'The above lifecycles should be removed. Learn more about this warning here:\n' +
'https://fb.me/react-unsafe-component-lifecycles',
);
}).toLowPriorityWarnDev(
}).toWarnDev(
[
'componentWillMount has been renamed',
'componentWillUpdate has been renamed',
Expand Down Expand Up @@ -956,7 +956,7 @@ describe('ReactComponentLifeCycle', () => {
'The above lifecycles should be removed. Learn more about this warning here:\n' +
'https://fb.me/react-unsafe-component-lifecycles',
);
}).toLowPriorityWarnDev(['componentWillMount has been renamed'], {
}).toWarnDev(['componentWillMount has been renamed'], {
withoutStack: true,
});

Expand All @@ -978,7 +978,7 @@ describe('ReactComponentLifeCycle', () => {
'The above lifecycles should be removed. Learn more about this warning here:\n' +
'https://fb.me/react-unsafe-component-lifecycles',
);
}).toLowPriorityWarnDev(['componentWillReceiveProps has been renamed'], {
}).toWarnDev(['componentWillReceiveProps has been renamed'], {
withoutStack: true,
});
});
Expand Down Expand Up @@ -1111,9 +1111,7 @@ describe('ReactComponentLifeCycle', () => {
}

const div = document.createElement('div');
expect(() =>
ReactDOM.render(<MyComponent foo="bar" />, div),
).toLowPriorityWarnDev(
expect(() => ReactDOM.render(<MyComponent foo="bar" />, div)).toWarnDev(
[
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
Expand Down Expand Up @@ -1382,9 +1380,7 @@ describe('ReactComponentLifeCycle', () => {
}

const container = document.createElement('div');
expect(() =>
ReactDOM.render(<MyComponent x={1} />, container),
).toLowPriorityWarnDev(
expect(() => ReactDOM.render(<MyComponent x={1} />, container)).toWarnDev(
[
/* eslint-disable max-len */
`Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('ReactCompositeComponent', () => {
// Old API based on heuristic
let container = document.createElement('div');
container.innerHTML = markup;
expect(() => ReactDOM.render(<Parent />, container)).toLowPriorityWarnDev(
expect(() => ReactDOM.render(<Parent />, container)).toWarnDev(
'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' +
'will stop working in React v17. Replace the ReactDOM.render() call ' +
'with ReactDOM.hydrate() if you want React to attach to the server HTML.',
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe('ReactDOMFiber', () => {
</div>,
container,
),
).toLowPriorityWarnDev(
).toWarnDev(
'The ReactDOM.unstable_createPortal() alias has been deprecated, ' +
'and will be removed in React 17+. Update your code to use ' +
'ReactDOM.createPortal() instead. It has the exact same API, ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ describe('ReactDOMServerLifecycles', () => {
}
}

expect(() =>
ReactDOMServer.renderToString(<Component />),
).toLowPriorityWarnDev('componentWillMount has been renamed');
expect(() => ReactDOMServer.renderToString(<Component />)).toWarnDev(
'componentWillMount has been renamed',
);
expect(log).toEqual(['componentWillMount', 'UNSAFE_componentWillMount']);
});

Expand Down Expand Up @@ -279,9 +279,9 @@ describe('ReactDOMServerLifecycles', () => {
}
}

expect(() =>
ReactDOMServer.renderToString(<Component />),
).toLowPriorityWarnDev('componentWillMount has been renamed');
expect(() => ReactDOMServer.renderToString(<Component />)).toWarnDev(
'componentWillMount has been renamed',
);
});

it('should warn about deprecated lifecycle hooks', () => {
Expand All @@ -292,9 +292,9 @@ describe('ReactDOMServerLifecycles', () => {
}
}

expect(() =>
ReactDOMServer.renderToString(<Component />),
).toLowPriorityWarnDev('componentWillMount has been renamed');
expect(() => ReactDOMServer.renderToString(<Component />)).toWarnDev(
'componentWillMount has been renamed',
);

// De-duped
ReactDOMServer.renderToString(<Component />);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/__tests__/ReactRenderDocument-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('rendering React components at document', () => {

describe('with old implicit hydration API', () => {
function expectDeprecationWarningWithFiber(callback) {
expect(callback).toLowPriorityWarnDev(
expect(callback).toWarnDev(
'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' +
'will stop working in React v17. Replace the ReactDOM.render() call ' +
'with ReactDOM.hydrate() if you want React to attach to the server HTML.',
Expand Down Expand Up @@ -197,7 +197,7 @@ describe('rendering React components at document', () => {
expect(() => {
expect(() =>
ReactDOM.render(<Component text="Hello world" />, testDocument),
).toLowPriorityWarnDev(
).toWarnDev(
'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' +
'will stop working in React v17. Replace the ReactDOM.render() call ' +
'with ReactDOM.hydrate() if you want React to attach to the server HTML.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('ReactDOMServerHydration', () => {

expect(() => {
instance = ReactDOM.render(<TestComponent name="x" />, element);
}).toLowPriorityWarnDev(
}).toWarnDev(
'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' +
'will stop working in React v17. Replace the ReactDOM.render() call ' +
'with ReactDOM.hydrate() if you want React to attach to the server HTML.',
Expand Down Expand Up @@ -355,12 +355,12 @@ describe('ReactDOMServerHydration', () => {
const element = document.createElement('div');
expect(() => {
element.innerHTML = ReactDOMServer.renderToString(markup);
}).toLowPriorityWarnDev('componentWillMount has been renamed');
}).toWarnDev('componentWillMount has been renamed');
expect(element.textContent).toBe('Hi');

expect(() => {
ReactDOM.hydrate(markup, element);
}).toLowPriorityWarnDev('componentWillMount has been renamed', {
}).toWarnDev('componentWillMount has been renamed', {
withoutStack: true,
});
expect(element.textContent).toBe('Hi');
Expand Down
4 changes: 1 addition & 3 deletions packages/react-dom/src/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ describe('ReactTestUtils', () => {
MockedComponent.prototype.render = jest.fn();

// Patch it up so it returns its children.
expect(() =>
ReactTestUtils.mockComponent(MockedComponent),
).toLowPriorityWarnDev(
expect(() => ReactTestUtils.mockComponent(MockedComponent)).toWarnDev(
'ReactTestUtils.mockComponent() is deprecated. ' +
'Use shallow rendering or jest.mock() instead.\n\n' +
'See https://fb.me/test-utils-mock-component for more information.',
Expand Down
8 changes: 2 additions & 6 deletions packages/react/src/__tests__/ReactES6Class-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,15 +521,11 @@ describe('ReactES6Class', () => {

it('should throw AND warn when trying to access classic APIs', () => {
const instance = test(<Inner name="foo" />, 'DIV', 'foo');
expect(() =>
expect(() => instance.replaceState({})).toThrow(),
).toLowPriorityWarnDev(
expect(() => expect(() => instance.replaceState({})).toThrow()).toWarnDev(
'replaceState(...) is deprecated in plain JavaScript React classes',
{withoutStack: true},
);
expect(() =>
expect(() => instance.isMounted()).toThrow(),
).toLowPriorityWarnDev(
expect(() => expect(() => instance.isMounted()).toThrow()).toWarnDev(
'isMounted(...) is deprecated in plain JavaScript React classes',
{withoutStack: true},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ describe('ReactElementValidator', () => {
}

let TestFactory = React.createFactory(TestComponent);
expect(() => TestFactory.type).toLowPriorityWarnDev(
expect(() => TestFactory.type).toWarnDev(
'Warning: Factory.type is deprecated. Access the class directly before ' +
'passing it to createFactory.',
{withoutStack: true},
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/__tests__/ReactStrictMode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ Please update the following components: AsyncRoot`,
],
{withoutStack: true},
);
}).toLowPriorityWarnDev(
}).toWarnDev(
[
/* eslint-disable max-len */
`Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('create-react-class-integration', () => {
render: () => null,
});

expect(() => ReactNative.render(<View />, 1)).toLowPriorityWarnDev(
expect(() => ReactNative.render(<View />, 1)).toWarnDev(
'componentWillMount has been renamed',
{withoutStack: true},
);
Expand All @@ -64,7 +64,7 @@ describe('create-react-class-integration', () => {
render: () => null,
});

expect(() => ReactNative.render(<View />, 1)).toLowPriorityWarnDev(
expect(() => ReactNative.render(<View />, 1)).toWarnDev(
'componentWillReceiveProps has been renamed',
{withoutStack: true},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ describe('create-react-class-integration', () => {
'The above lifecycles should be removed. Learn more about this warning here:\n' +
'https://fb.me/react-unsafe-component-lifecycles',
);
}).toLowPriorityWarnDev(
}).toWarnDev(
[
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
Expand Down Expand Up @@ -598,7 +598,7 @@ describe('create-react-class-integration', () => {
'The above lifecycles should be removed. Learn more about this warning here:\n' +
'https://fb.me/react-unsafe-component-lifecycles',
);
}).toLowPriorityWarnDev(
}).toWarnDev(
[
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
Expand Down Expand Up @@ -641,9 +641,7 @@ describe('create-react-class-integration', () => {
});

const div = document.createElement('div');
expect(() =>
ReactDOM.render(<Component foo="bar" />, div),
).toLowPriorityWarnDev(
expect(() => ReactDOM.render(<Component foo="bar" />, div)).toWarnDev(
[
'componentWillMount has been renamed',
'componentWillReceiveProps has been renamed',
Expand Down
3 changes: 1 addition & 2 deletions scripts/jest/matchers/toWarnDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ const createMatcherFor = (consoleMethod, matcherName) =>
};

module.exports = {
// TODO: rename this one.
toLowPriorityWarnDev: createMatcherFor('warn', 'toLowPriorityWarnDev'),
toWarnDev: createMatcherFor('warn', 'toWarnDev'),
toErrorDev: createMatcherFor('error', 'toErrorDev'),
};

0 comments on commit 35313aa

Please sign in to comment.