Skip to content

Commit

Permalink
chore(test) add test for copyToClipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol committed Aug 28, 2023
1 parent 4d9dfcf commit 604c480
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
'!src/core/constants/*.{ts,tsx}',
'!src/generated/*.{ts,tsx}',
'!src/styles/**',
'!src/pages/__devOnly/*.{ts,tsx}',
],
coverageReporters: ['text', 'lcov'],
collectCoverage: false, // set to true to collect coverage
Expand Down
17 changes: 17 additions & 0 deletions src/core/utils/__tests__/copyToClipboard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { copyToClipboard } from '../copyToClipboard'

Object.assign(window.navigator, {
clipboard: {
writeText: jest.fn().mockImplementation(() => Promise.resolve()),
},
})

describe('copyToClipboard', () => {
it('should copy to clipboard', () => {
copyToClipboard('the text that needs to be copied')

expect(window.navigator.clipboard.writeText).toHaveBeenCalledWith(
'the text that needs to be copied'
)
})
})

0 comments on commit 604c480

Please sign in to comment.