fix(tests): unsupported clipboard in certain environment

This commit is contained in:
Phan An 2024-09-05 12:30:56 +02:00
parent 4ec274d1a6
commit d73028fb0c
2 changed files with 7 additions and 2 deletions

View file

@ -56,3 +56,9 @@ window.SSO_PROVIDERS = []
window.createLemonSqueezy = vi.fn()
Axios.defaults.adapter = vi.fn()
Object.assign(navigator, {
clipboard: {
writeText: vi.fn()
}
})

View file

@ -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!')
})
})