diff --git a/ui/src/index.test.js b/ui/src/index.test.js index f46d8fb1f..acb9fe90a 100644 --- a/ui/src/index.test.js +++ b/ui/src/index.test.js @@ -38,4 +38,17 @@ describe("console", () => { console.warn(); }).toThrowError("message=undefined args="); }); + + it("console.warn() with React deprecation warning doesn't throw any error", () => { + // https://reactjs.org/blog/2019/08/08/react-v16.9.0.html#new-deprecations + const msg = [ + "Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.", + "* Move code with side effects to componentDidMount, and set initial state in the constructor.", + "* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.", + "Please update the following components: foo" + ].join("\n"); + expect(() => { + console.warn(msg); + }).not.toThrow(); + }); }); diff --git a/ui/src/setupTests.js b/ui/src/setupTests.js index b1c5defd8..1233ffcd8 100644 --- a/ui/src/setupTests.js +++ b/ui/src/setupTests.js @@ -16,7 +16,11 @@ global.fetch = require("jest-fetch-mock"); // ensure that all console messages throw errors for (const level of ["error", "warn", "info", "log", "trace"]) { + // https://reactjs.org/blog/2019/08/08/react-v16.9.0.html#new-deprecations + const reactDeprecationWarning = /.*has been renamed, and is not recommended for use\. See https:\/\/fb.me\/react-async-component-lifecycle-hooks for details.*/; global.console[level] = (message, ...args) => { - throw new Error(`message=${message} args=${args}`); + if (reactDeprecationWarning.test(message) === false) { + throw new Error(`message=${message} args=${args}`); + } }; }