Commit fbe1f8b4 authored by Winnie Hellmann's avatar Winnie Hellmann

Provide custom Jest environment with mocked console

parent f9f5ebc2
...@@ -37,4 +37,5 @@ module.exports = { ...@@ -37,4 +37,5 @@ module.exports = {
}, },
transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui)/)'], transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui)/)'],
timers: 'fake', timers: 'fake',
testEnvironment: '<rootDir>/spec/frontend/environment.js',
}; };
/* 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;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment