summaryrefslogtreecommitdiff
path: root/spec/frontend/helpers/jquery.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/helpers/jquery.js')
-rw-r--r--spec/frontend/helpers/jquery.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/frontend/helpers/jquery.js b/spec/frontend/helpers/jquery.js
index 6421a592c0c..4af5f904394 100644
--- a/spec/frontend/helpers/jquery.js
+++ b/spec/frontend/helpers/jquery.js
@@ -1,6 +1,18 @@
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.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 $;