privacy-html';
- };
+ });
stream_list.redraw_stream_privacy(social);
assert.equal(privacy_elem.html(), '
privacy-html');
@@ -693,7 +691,7 @@ run_test('rename_stream', () => {
const li_stub = $.create('li stub');
li_stub.length = 0;
- templates.render = (name, payload) => {
+ global.stub_templates((name, payload) => {
assert.equal(name, 'stream_sidebar_row');
assert.deepEqual(payload, {
name: 'Development',
@@ -707,7 +705,7 @@ run_test('rename_stream', () => {
dark_background: payload.dark_background,
});
return {to_$: () => li_stub};
- };
+ });
var count_updated;
stream_list.update_count_in_dom = (li) => {
@@ -740,9 +738,9 @@ run_test('refresh_pin', () => {
const li_stub = $.create('li stub');
li_stub.length = 0;
- templates.render = () => {
+ global.stub_templates(() => {
return {to_$: () => li_stub};
- };
+ });
stream_list.update_count_in_dom = noop;
$('#stream_filters').append = noop;
@@ -771,10 +769,10 @@ run_test('create_initial_sidebar_rows', () => {
stream_list.update_count_in_dom = noop;
- global.templates.render = function (template_name, data) {
+ global.stub_templates(function (template_name, data) {
assert.equal(template_name, 'stream_sidebar_row');
return '
stub-html-' + data.name;
- };
+ });
// Test this code with stubs above...
stream_list.create_initial_sidebar_rows();
diff --git a/frontend_tests/node_tests/subs.js b/frontend_tests/node_tests/subs.js
index 5a11174546..1cb727f321 100644
--- a/frontend_tests/node_tests/subs.js
+++ b/frontend_tests/node_tests/subs.js
@@ -1,6 +1,5 @@
global.stub_out_jquery();
-set_global('templates', {});
set_global('ui', {
get_content_element: element => element,
get_scroll_element: element => element,
@@ -71,10 +70,10 @@ run_test('filter_table', () => {
var populated_subs;
- templates.render = (fn, data) => {
+ global.stub_templates((fn, data) => {
assert.equal(fn, 'subscriptions');
populated_subs = data.subscriptions;
- };
+ });
subs.populate_stream_settings_left_panel();
diff --git a/frontend_tests/node_tests/topic_list.js b/frontend_tests/node_tests/topic_list.js
index fdc9babf69..d3a3031182 100644
--- a/frontend_tests/node_tests/topic_list.js
+++ b/frontend_tests/node_tests/topic_list.js
@@ -5,7 +5,6 @@ set_global('narrow_state', {});
set_global('unread', {});
set_global('muting', {});
set_global('stream_popover', {});
-set_global('templates', {});
set_global('message_list', {});
zrequire('hash_util');
@@ -43,7 +42,7 @@ run_test('topic_list_build_widget', () => {
var checked_mutes;
var rendered;
- templates.render = function (name, info) {
+ global.stub_templates(function (name, info) {
assert.equal(name, 'topic_list_item');
var expected = {
topic_name: 'coding',
@@ -55,7 +54,7 @@ run_test('topic_list_build_widget', () => {
assert.deepEqual(info, expected);
rendered = true;
return '
';
- };
+ });
muting.is_topic_muted = function (stream_id, topic_name) {
assert.equal(stream_id, devel.stream_id);
diff --git a/frontend_tests/node_tests/typeahead_helper.js b/frontend_tests/node_tests/typeahead_helper.js
index fc7fd478b4..8492675645 100644
--- a/frontend_tests/node_tests/typeahead_helper.js
+++ b/frontend_tests/node_tests/typeahead_helper.js
@@ -1,6 +1,5 @@
set_global('i18n', global.stub_i18n);
set_global('page_params', {realm_is_zephyr_mirror_realm: false});
-set_global('templates', {});
set_global('md5', function (s) {
return 'md5-' + s;
});
@@ -413,13 +412,13 @@ run_test('render_person when emails hidden', () => {
// Test render_person with regular person, under hidden email visiblity case
settings_org.show_email = () => false;
var rendered = false;
- global.templates.render = function (template_name, args) {
+ global.stub_templates(function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, matches[2].full_name);
assert.equal(args.secondary, undefined);
rendered = true;
return 'typeahead-item-stub';
- };
+ });
assert.equal(th.render_person(matches[2]), 'typeahead-item-stub');
assert(rendered);
});
@@ -428,13 +427,13 @@ run_test('render_person', () => {
settings_org.show_email = () => true;
// Test render_person with regular person
var rendered = false;
- global.templates.render = function (template_name, args) {
+ global.stub_templates(function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, matches[1].full_name);
assert.equal(args.secondary, matches[1].email);
rendered = true;
return 'typeahead-item-stub';
- };
+ });
assert.equal(th.render_person(matches[1]), 'typeahead-item-stub');
assert(rendered);
@@ -448,25 +447,25 @@ run_test('render_person', () => {
special_item_text: "special_text",
};
rendered = false;
- global.templates.render = function (template_name, args) {
+ global.stub_templates(function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, special_person.special_item_text);
rendered = true;
return 'typeahead-item-stub';
- };
+ });
assert.equal(th.render_person(special_person), 'typeahead-item-stub');
assert(rendered);
});
run_test('clear_rendered_person', () => {
var rendered = false;
- global.templates.render = function (template_name, args) {
+ global.stub_templates(function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, matches[5].full_name);
assert.equal(args.secondary, matches[5].email);
rendered = true;
return 'typeahead-item-stub';
- };
+ });
assert.equal(th.render_person(matches[5]), 'typeahead-item-stub');
assert(rendered);
@@ -492,13 +491,13 @@ run_test('render_stream', () => {
stream_id: 42,
name: 'Short Description',
};
- global.templates.render = function (template_name, args) {
+ global.stub_templates(function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, stream.name);
assert.equal(args.secondary, stream.description);
rendered = true;
return 'typeahead-item-stub';
- };
+ });
assert.equal(th.render_stream(stream), 'typeahead-item-stub');
assert(rendered);
@@ -509,14 +508,14 @@ run_test('render_stream', () => {
stream_id: 43,
name: 'Long Description',
};
- global.templates.render = function (template_name, args) {
+ global.stub_templates(function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, stream.name);
var short_desc = stream.description.substring(0, 35);
assert.equal(args.secondary, short_desc + "...");
rendered = true;
return 'typeahead-item-stub';
- };
+ });
assert.equal(th.render_stream(stream), 'typeahead-item-stub');
assert(rendered);
});
@@ -532,7 +531,7 @@ run_test('render_emoji', () => {
realm_emoji: 'TBD',
};
- global.templates.render = function (template_name, args) {
+ global.stub_templates(function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
assert.deepEqual(args, {
primary: 'thumbs up',
@@ -543,7 +542,7 @@ run_test('render_emoji', () => {
});
rendered = true;
return 'typeahead-item-stub';
- };
+ });
assert.equal(th.render_emoji(test_emoji), 'typeahead-item-stub');
assert(rendered);
@@ -554,7 +553,7 @@ run_test('render_emoji', () => {
emoji_url: 'TBD',
};
- global.templates.render = function (template_name, args) {
+ global.stub_templates(function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
assert.deepEqual(args, {
primary: 'realm emoji',
@@ -565,7 +564,7 @@ run_test('render_emoji', () => {
});
rendered = true;
return 'typeahead-item-stub';
- };
+ });
assert.equal(th.render_emoji(test_emoji), 'typeahead-item-stub');
assert(rendered);
});
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
index 6915e01e88..37ecfca997 100644
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -33,7 +33,6 @@ set_global('$', () => {});
set_global('resize', {});
set_global('feature_flags', {});
set_global('page_params', {});
-set_global('templates', {});
const ignore_modules = [
'activity',
@@ -73,7 +72,7 @@ _.each(ignore_modules, (mod) => {
zrequire('util');
util.is_mobile = () => false;
-templates.render = () => 'some-html';
+global.stub_templates(() => 'some-html');
ui.get_scroll_element = element => element;
zrequire('echo');
diff --git a/frontend_tests/node_tests/voting_widget.js b/frontend_tests/node_tests/voting_widget.js
index 19de15c8ec..ccf4ce9b67 100644
--- a/frontend_tests/node_tests/voting_widget.js
+++ b/frontend_tests/node_tests/voting_widget.js
@@ -5,7 +5,6 @@ set_global('i18n', global.stub_i18n);
set_global('people', {});
set_global('blueslip', global.make_zblueslip());
-set_global('templates', {});
const noop = () => {};
const return_false = () => false;
@@ -140,14 +139,14 @@ run_test('poll_data_holder my question', () => {
run_test('activate another person poll', () => {
people.is_my_user_id = return_false;
- templates.render = (template_name) => {
+ global.stub_templates((template_name) => {
if (template_name === 'widgets/poll_widget') {
return 'widgets/poll_widget';
}
if (template_name === 'widgets/poll_widget_results') {
return 'widgets/poll_widget_results';
}
- };
+ });
const widget_elem = $('').addClass('widget-content');
@@ -305,14 +304,14 @@ run_test('activate own poll', () => {
$.clear_all_elements();
people.is_my_user_id = return_true;
- templates.render = (template_name) => {
+ global.stub_templates((template_name) => {
if (template_name === 'widgets/poll_widget') {
return 'widgets/poll_widget';
}
if (template_name === 'widgets/poll_widget_results') {
return 'widgets/poll_widget_results';
}
- };
+ });
const widget_elem = $('
').addClass('widget-content');
let out_data;
diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js
index 1af0e81dda..f91ad2cdfd 100644
--- a/frontend_tests/zjsunit/index.js
+++ b/frontend_tests/zjsunit/index.js
@@ -67,6 +67,12 @@ global.make_zblueslip = require('./zblueslip.js').make_zblueslip;
// Set up fake translation
global.stub_i18n = require('./i18n.js');
+// Set up Handlebars
+global.stub_templates = stub => {
+ set_global('templates', {});
+ templates.render = stub;
+};
+
var noop = function () {};
// Set up fake module.hot