diff options
author | Phil Hughes <me@iamphill.com> | 2019-03-27 11:37:25 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-03-27 11:37:25 +0300 |
commit | 3bdd7ff4273c69440fa1cd88a67d53f2ec6c8435 (patch) | |
tree | a004c00b2078da7444a59b746a5c072168f69c37 /spec | |
parent | 581b839fe557f0e026004d7064829f1167646838 (diff) | |
parent | fbe1f8b4cb7cfca5aa6a6a1cd36600e77f52cf68 (diff) |
Merge branch 'winh-jest-console' into 'master'
Provide custom Jest environment with mocked console
Closes #58203
See merge request gitlab-org/gitlab-ce!26577
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/environment.js | 27 | ||||
-rw-r--r-- | spec/frontend/helpers/fixtures.js | 2 |
2 files changed, 27 insertions, 2 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; diff --git a/spec/frontend/helpers/fixtures.js b/spec/frontend/helpers/fixtures.js index f96f27c4d80..de9058d7832 100644 --- a/spec/frontend/helpers/fixtures.js +++ b/spec/frontend/helpers/fixtures.js @@ -3,8 +3,6 @@ import fs from 'fs'; import path from 'path'; -// jest-util is part of Jest -// eslint-disable-next-line import/no-extraneous-dependencies import { ErrorWithStack } from 'jest-util'; const fixturesBasePath = path.join(process.cwd(), 'spec', 'javascripts', 'fixtures'); |