Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinnie Hellmann <winnie@gitlab.com>2019-03-26 22:49:05 +0300
committerWinnie Hellmann <winnie@gitlab.com>2019-03-26 22:49:05 +0300
commitfbe1f8b4cb7cfca5aa6a6a1cd36600e77f52cf68 (patch)
tree1344ab2ccb9940147013f08c3a2a3ea1b4c358d0 /spec/frontend/environment.js
parentf9f5ebc2ac751ceb288381d1792aecec43bdbe39 (diff)
Provide custom Jest environment with mocked console
Diffstat (limited to 'spec/frontend/environment.js')
-rw-r--r--spec/frontend/environment.js27
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;