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(); + }); });