From 215df2a5d65c70e74890a9e6d78f8b078a16b2c2 Mon Sep 17 00:00:00 2001 From: Geoff Cox Date: Sun, 10 Oct 2021 15:46:15 -0700 Subject: [PATCH] test(jest): fail on console error or warn --- src/setupTests.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/setupTests.js b/src/setupTests.js index 1bc5ba98..8e34fdb8 100644 --- a/src/setupTests.js +++ b/src/setupTests.js @@ -11,6 +11,20 @@ function createMatchMedia(width) { }); } +// Fail tests on any console error +const error = console.error; +console.error = function (message) { + error.apply(console, arguments); // keep default behaviour + throw message; +}; + +// Fail tests on any console warn +const warn = console.warn; +console.warn = function (message) { + warn.apply(console, arguments); // keep default behaviour + throw message; +}; + // Currently needed to support Material UI's withMobileDialog, etc... See // https://material-ui.com/components/use-media-query/#testing global.window.matchMedia = createMatchMedia(window.innerWidth);