Provide custom Jest environment with mocked console
This commit is contained in:
parent
f9f5ebc2ac
commit
fbe1f8b4cb
2 changed files with 28 additions and 0 deletions
|
@ -37,4 +37,5 @@ module.exports = {
|
|||
},
|
||||
transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui)/)'],
|
||||
timers: 'fake',
|
||||
testEnvironment: '<rootDir>/spec/frontend/environment.js',
|
||||
};
|
||||
|
|
27
spec/frontend/environment.js
Normal file
27
spec/frontend/environment.js
Normal file
|
@ -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;
|
Loading…
Reference in a new issue