diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2019-03-26 20:49:05 +0100 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2019-03-26 20:49:05 +0100 |
commit | fbe1f8b4cb7cfca5aa6a6a1cd36600e77f52cf68 (patch) | |
tree | 1344ab2ccb9940147013f08c3a2a3ea1b4c358d0 /spec | |
parent | f9f5ebc2ac751ceb288381d1792aecec43bdbe39 (diff) | |
download | gitlab-ce-fbe1f8b4cb7cfca5aa6a6a1cd36600e77f52cf68.tar.gz |
Provide custom Jest environment with mocked console
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/environment.js | 27 |
1 files changed, 27 insertions, 0 deletions
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; |