Skip to content

Commit

Permalink
fix: testing subscriber button click test
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmcguire1 committed Jun 14, 2024
1 parent e7814d1 commit ca7d366
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/utils/CustomMetric.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<BListGroupItem>
<div>
<BContainer class="text-center">
<BButton @click="subscribeToUser()"
<BButton id="subscribeBtn" @click="subscribeToUser()"
>Subscribe to {{ channelName }}</BButton
>
</BContainer>
Expand Down
31 changes: 31 additions & 0 deletions tests/CustomMetric.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit ca7d366

Please sign in to comment.