diff options
-rw-r--r-- | jest.config.js | 1 | ||||
-rw-r--r-- | spec/frontend/environment.js | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/jest.config.js b/jest.config.js index 1f6e04390ae..cd0d311779d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -37,4 +37,5 @@ module.exports = { }, transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui)/)'], timers: 'fake', + testEnvironment: '<rootDir>/spec/frontend/environment.js', }; diff --git a/spec/frontend/environment.js b/spec/frontend/environment.js new file mode 100644 index 00000000000..cb128c7d880 --- /dev/null +++ b/spec/frontend/environment.js @@ -0,0 +1,27 @@ +/* eslint-disable import/no-commonjs */ + +const { ErrorWithStack } = require('jest-util'); +const JSDOMEnvironment = require('jest-environment-jsdom'); + +class CustomEnvironment extends JSDOMEnvironment { + constructor(config, context) { + super(config, context); + Object.assign(context.console, { + error(...args) { + throw new ErrorWithStack( + `Unexpected call of console.error() with:\n\n${args.join(', ')}`, + this.error, + ); + }, + + warn(...args) { + throw new ErrorWithStack( + `Unexpected call of console.warn() with:\n\n${args.join(', ')}`, + this.warn, + ); + }, + }); + } +} + +module.exports = CustomEnvironment; |