From 0b4338b99823590f4c65a18c878a90397707879e Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 11 Jun 2021 13:32:35 +0000 Subject: [PATCH] node tests: Use mock_template in poll_widget. --- frontend_tests/node_tests/poll_widget.js | 32 ++++++++---------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/frontend_tests/node_tests/poll_widget.js b/frontend_tests/node_tests/poll_widget.js index bd57e71f8e..e70aec475b 100644 --- a/frontend_tests/node_tests/poll_widget.js +++ b/frontend_tests/node_tests/poll_widget.js @@ -2,8 +2,7 @@ const {strict: assert} = require("assert"); -const {stub_templates} = require("../zjsunit/handlebars"); -const {mock_cjs, zrequire} = require("../zjsunit/namespace"); +const {mock_cjs, mock_template, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const blueslip = require("../zjsunit/zblueslip"); const $ = require("../zjsunit/zjquery"); @@ -12,6 +11,9 @@ const {PollData} = zrequire("../../static/shared/js/poll_data"); mock_cjs("jquery", $); +const render_poll_widget = mock_template("widgets/poll_widget.hbs"); +const render_poll_widget_results = mock_template("widgets/poll_widget_results.hbs"); + const poll_widget = zrequire("poll_widget"); const people = zrequire("people"); @@ -179,16 +181,9 @@ run_test("PollData my question", () => { }); }); -run_test("activate another person poll", () => { - 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"; - } - throw new Error(`Unknown template ${template_name}`); - }); +run_test("activate another person poll", (override) => { + override(render_poll_widget, "f", () => "widgets/poll_widget"); + override(render_poll_widget_results, "f", () => "widgets/poll_widget_results"); const widget_elem = $("
").addClass("widget-content"); @@ -301,16 +296,9 @@ run_test("activate another person poll", () => { widget_elem.handle_events(add_question_event); }); -run_test("activate own poll", () => { - 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"; - } - throw new Error(`Unknown template ${template_name}`); - }); +run_test("activate own poll", (override) => { + override(render_poll_widget, "f", () => "widgets/poll_widget"); + override(render_poll_widget_results, "f", () => "widgets/poll_widget_results"); const widget_elem = $("
").addClass("widget-content"); let out_data;