From d73028fb0c066b30ca45f25db9dc2cbd58080e4e Mon Sep 17 00:00:00 2001 From: Phan An Date: Thu, 5 Sep 2024 12:30:56 +0200 Subject: [PATCH] fix(tests): unsupported clipboard in certain environment --- resources/assets/js/__tests__/setup.ts | 6 ++++++ .../components/playlist/InvitePlaylistContributors.spec.ts | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/resources/assets/js/__tests__/setup.ts b/resources/assets/js/__tests__/setup.ts index d1edcd5b..220e4f6a 100644 --- a/resources/assets/js/__tests__/setup.ts +++ b/resources/assets/js/__tests__/setup.ts @@ -56,3 +56,9 @@ window.SSO_PROVIDERS = [] window.createLemonSqueezy = vi.fn() Axios.defaults.adapter = vi.fn() + +Object.assign(navigator, { + clipboard: { + writeText: vi.fn() + } +}) diff --git a/resources/assets/js/components/playlist/InvitePlaylistContributors.spec.ts b/resources/assets/js/components/playlist/InvitePlaylistContributors.spec.ts index 7a25848a..133d8563 100644 --- a/resources/assets/js/components/playlist/InvitePlaylistContributors.spec.ts +++ b/resources/assets/js/components/playlist/InvitePlaylistContributors.spec.ts @@ -9,7 +9,6 @@ new class extends UnitTestCase { protected test () { it('works', async () => { this.mock(playlistCollaborationService, 'createInviteLink').mockResolvedValue('http://localhost:3000/invite/1234') - const writeTextMock = this.mock(navigator.clipboard, 'writeText') const playlist = factory('playlist') this.render(Component, { @@ -21,7 +20,7 @@ new class extends UnitTestCase { await this.user.click(screen.getByText('Invite')) await waitFor(async () => { - expect(writeTextMock).toHaveBeenCalledWith('http://localhost:3000/invite/1234') + expect(navigator.clipboard.writeText).toHaveBeenCalledWith('http://localhost:3000/invite/1234') screen.getByText('Link copied to clipboard!') }) })