This repository was archived by the owner on Jan 11, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ import { copyToTheClipboard } from "../clipboard" ;
2+
3+ let clipboardTestCopyString , expectedCopyEvent ;
4+ const addEventListener = jest . fn ( ) ;
5+ const execCommand = jest . fn ( ) ;
6+ const removeEventListener = jest . fn ( ) ;
7+
8+ describe ( "copyToTheClipboard()" , ( ) => {
9+ beforeEach ( ( ) => {
10+ expectedCopyEvent = "copy" ;
11+ clipboardTestCopyString = "content intended for clipboard" ;
12+
13+ global . document . addEventListener = addEventListener ;
14+ global . document . execCommand = execCommand ;
15+ global . document . removeEventListener = removeEventListener ;
16+ } ) ;
17+
18+ it ( "listens for 'copy' event" , ( ) => {
19+ copyToTheClipboard ( clipboardTestCopyString ) ;
20+
21+ expect ( document . addEventListener ) . toHaveBeenCalledWith (
22+ expectedCopyEvent ,
23+ expect . anything ( )
24+ ) ;
25+ } ) ;
26+
27+ it ( "calls document.execCommand() with 'copy' command" , ( ) => {
28+ copyToTheClipboard ( clipboardTestCopyString ) ;
29+
30+ expect ( execCommand ) . toHaveBeenCalledWith ( expectedCopyEvent , false , null ) ;
31+ } ) ;
32+
33+ it ( "removes event listener for 'copy' event" , ( ) => {
34+ copyToTheClipboard ( clipboardTestCopyString ) ;
35+
36+ expect ( document . removeEventListener ) . toHaveBeenCalledWith (
37+ expectedCopyEvent ,
38+ expect . anything ( )
39+ ) ;
40+ } ) ;
41+ } ) ;
You can’t perform that action at this time.
0 commit comments