diff --git a/jest.config.js b/jest.config.js index 1f6e04390ae309c435cb5d318a530da1e7547da2..cd0d311779db5a22d6a7b3254fef4810ecfbd6fd 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 0000000000000000000000000000000000000000..cb128c7d88098edba5e88ed81674ea12623f6678 --- /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;