Commit d7a1f22c authored by Paul Slaughter's avatar Paul Slaughter

Move jest jquery setup and add commons import

- This loads all of our default jquery plugins
- This also removes the need for our custom mocker to
  handle node_modules things
- Originally I wanted to import just ~/commons but this
  seems to load some modules which depend on API and broke
  the mocking in those tests
  (user_merge_requests_spec)
parent 0eef93f9
import $ from 'jquery'; import $ from 'jquery';
// Expose jQuery so specs using jQuery plugins can be imported nicely.
// Here is an issue to explore better alternatives:
// https://gitlab.com/gitlab-org/gitlab/issues/12448
global.$ = $; global.$ = $;
global.jQuery = $; global.jQuery = $;
// Fail tests for unmocked requests
$.ajax = () => {
const err = new Error(
'Unexpected unmocked jQuery.ajax() call! Make sure to mock jQuery.ajax() in tests.',
);
global.fail(err);
throw err;
};
export default $; export default $;
/* eslint-disable import/no-commonjs */
const $ = jest.requireActual('jquery');
// Fail tests for unmocked requests
$.ajax = () => {
const err = new Error(
'Unexpected unmocked jQuery.ajax() call! Make sure to mock jQuery.ajax() in tests.',
);
global.fail(err);
throw err;
};
// jquery is not an ES6 module
module.exports = $;
import Vue from 'vue'; import Vue from 'vue';
import * as jqueryMatchers from 'custom-jquery-matchers'; import * as jqueryMatchers from 'custom-jquery-matchers';
import $ from 'jquery';
import { config as testUtilsConfig } from '@vue/test-utils'; import { config as testUtilsConfig } from '@vue/test-utils';
import Translate from '~/vue_shared/translate'; import Translate from '~/vue_shared/translate';
import { initializeTestTimeout } from './helpers/timeout'; import { initializeTestTimeout } from './helpers/timeout';
...@@ -9,11 +8,9 @@ import { setupManualMocks } from './mocks/mocks_helper'; ...@@ -9,11 +8,9 @@ import { setupManualMocks } from './mocks/mocks_helper';
import customMatchers from './matchers'; import customMatchers from './matchers';
import './helpers/dom_shims'; import './helpers/dom_shims';
import './helpers/jquery';
// Expose jQuery so specs using jQuery plugins can be imported nicely. import '~/commons/jquery';
// Here is an issue to explore better alternatives: import '~/commons/bootstrap';
// https://gitlab.com/gitlab-org/gitlab/issues/12448
window.jQuery = $;
process.on('unhandledRejection', global.promiseRejectionHandler); process.on('unhandledRejection', global.promiseRejectionHandler);
......
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