From ca7d366002c74ff07367b04213280e818fe82a10 Mon Sep 17 00:00:00 2001 From: jackmc Date: Fri, 14 Jun 2024 10:07:11 +0100 Subject: [PATCH] fix: testing subscriber button click test --- src/components/utils/CustomMetric.vue | 2 +- tests/CustomMetric.spec.js | 31 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/utils/CustomMetric.vue b/src/components/utils/CustomMetric.vue index 2acd027..6d753cc 100644 --- a/src/components/utils/CustomMetric.vue +++ b/src/components/utils/CustomMetric.vue @@ -44,7 +44,7 @@
- Subscribe to {{ channelName }} diff --git a/tests/CustomMetric.spec.js b/tests/CustomMetric.spec.js index 03b493d..5580413 100644 --- a/tests/CustomMetric.spec.js +++ b/tests/CustomMetric.spec.js @@ -84,4 +84,35 @@ describe("CustomMetric.vue", () => { }); expect(wrapper.text()).not.toContain("Subscribe to Dummy Channel"); }); + + it("calls window.open when subscribe button is clicked", async () => { + const windowOpenSpy = jest + .spyOn(window, "open") + .mockImplementation(() => {}); + + const wrapper = shallowMount(CustomMetric, { + propsData: { + title, + description, + target: 10, + count: 5, + gauge_colour, + displaySubButton: true, + displayFollowButton, + buttonTxtColour, + buttonBkgColour, + channelName, + }, + }); + + await wrapper.find("#subscribeBtn").trigger("click"); + + expect(windowOpenSpy).toHaveBeenCalled(); + expect(windowOpenSpy).toHaveBeenCalledWith( + "https://subs.twitch.tv/" + channelName, + "_blank" + ); + + windowOpenSpy.mockRestore(); + }); });