Skip to content

Commit

Permalink
fix(tests): unsupported clipboard in certain environment
Browse files Browse the repository at this point in the history
  • Loading branch information
phanan committed Sep 5, 2024
1 parent 4ec274d commit d73028f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 6 additions & 0 deletions resources/assets/js/__tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ window.SSO_PROVIDERS = []
window.createLemonSqueezy = vi.fn()

Axios.defaults.adapter = vi.fn()

Object.assign(navigator, {
clipboard: {
writeText: vi.fn()
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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!')
})
})
Expand Down

0 comments on commit d73028f

Please sign in to comment.