diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js index 6bce79e38b..9924bcee5d 100644 --- a/frontend_tests/node_tests/activity.js +++ b/frontend_tests/node_tests/activity.js @@ -1,11 +1,4 @@ -set_global('$', function () { - return { - on: function () { - return; - } - }; -}); -$.fn = {}; +global.stub_out_jquery(); add_dependencies({ util: 'js/util.js', diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js index 1ccdec61f7..d3c6582060 100644 --- a/frontend_tests/node_tests/echo.js +++ b/frontend_tests/node_tests/echo.js @@ -2,13 +2,7 @@ var path = require('path'); var fs = require('fs'); -set_global('$', function () { - return { - on: function () { - return; - } - }; -}); +global.stub_out_jquery(); set_global('page_params', {realm_emoji: { burrito: {display_url: '/static/third/gemoji/images/emoji/burrito.png', diff --git a/frontend_tests/node_tests/message_list.js b/frontend_tests/node_tests/message_list.js index 1d895d6212..ba7f472fc1 100644 --- a/frontend_tests/node_tests/message_list.js +++ b/frontend_tests/node_tests/message_list.js @@ -10,12 +10,8 @@ add_dependencies({ set_global('document', null); -set_global('$', function () { - return { - on: function () {}, - trigger: function () {} - }; -}); + +global.stub_out_jquery(); set_global('feature_flags', {}); set_global('Filter', function () {}); diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js index 9ff9b32099..2e622a9a44 100644 --- a/frontend_tests/node_tests/people.js +++ b/frontend_tests/node_tests/people.js @@ -2,13 +2,7 @@ add_dependencies({ util: 'js/util.js' }); -set_global('$', function () { - return { - on: function () { - return; - } - }; -}); +global.stub_out_jquery(); var people = require("js/people.js"); diff --git a/frontend_tests/node_tests/presence_list_performance.js b/frontend_tests/node_tests/presence_list_performance.js index 80defe1ed4..9512a20174 100644 --- a/frontend_tests/node_tests/presence_list_performance.js +++ b/frontend_tests/node_tests/presence_list_performance.js @@ -1,12 +1,5 @@ // TODO: de-dup with activity.js -set_global('$', function () { - return { - on: function () { - return; - } - }; -}); -$.fn = {}; +global.stub_out_jquery(); set_global('document', { hasFocus: function () { diff --git a/frontend_tests/node_tests/server_events.js b/frontend_tests/node_tests/server_events.js index 2f27ce6674..e8e0dce289 100644 --- a/frontend_tests/node_tests/server_events.js +++ b/frontend_tests/node_tests/server_events.js @@ -11,13 +11,8 @@ set_global('document', {}); set_global('window', { addEventListener: noop }); -set_global('$', function () { - return { - hide: noop, - trigger: noop - }; -}); -global.$.now = noop; + +global.stub_out_jquery(); // Prevent the get_events loop and watchdog from running patch_builtin('setTimeout', noop); diff --git a/frontend_tests/node_tests/stream_color.js b/frontend_tests/node_tests/stream_color.js index a378c03b09..f499c59851 100644 --- a/frontend_tests/node_tests/stream_color.js +++ b/frontend_tests/node_tests/stream_color.js @@ -1,4 +1,4 @@ -set_global('$', function (f) {}); +global.stub_out_jquery(); var stream_color = require('js/stream_color.js'); diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index b63a86a2b8..9d7257b366 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -1,4 +1,4 @@ -set_global('$', function () {}); +global.stub_out_jquery(); add_dependencies({ Handlebars: 'handlebars', diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index 0d6b1b2e41..a04e3b54c3 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -17,6 +17,7 @@ var namespace = require('./namespace.js'); global.set_global = namespace.set_global; global.patch_builtin = namespace.patch_builtin; global.add_dependencies = namespace.add_dependencies; +global.stub_out_jquery = namespace.stub_out_jquery; // Set up helpers to render templates. var render = require('./render.js'); diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js index 82b5ab8fb0..0efcaf9631 100644 --- a/frontend_tests/zjsunit/namespace.js +++ b/frontend_tests/zjsunit/namespace.js @@ -39,6 +39,18 @@ exports.restore = function () { old_builtins = {}; }; +exports.stub_out_jquery = function () { + set_global('$', function () { + return { + on: function () {}, + trigger: function () {}, + hide: function () {} + }; + }); + $.fn = {}; + $.now = function () {}; +}; + return exports; }()); module.exports = namespace;