@@ -7,9 +7,9 @@ import { MarkdownCodeBlock } from "./MarkdownCodeBlock";
77import { MarkdownTable } from "./MarkdownTable" ;
88
99// Insecure origins (a LAN or tailnet address over plain http) have no async clipboard.
10- function withoutAsyncClipboard ( ) {
10+ function withoutAsyncClipboard ( clipboard ?: Partial < Clipboard > ) {
1111 const original = Object . getOwnPropertyDescriptor ( Navigator . prototype , "clipboard" ) ;
12- Object . defineProperty ( navigator , "clipboard" , { configurable : true , value : undefined } ) ;
12+ Object . defineProperty ( navigator , "clipboard" , { configurable : true , value : clipboard } ) ;
1313 const copied = new DataTransfer ( ) ;
1414 const execCommand = vi . spyOn ( document , "execCommand" ) . mockImplementation ( ( ) => {
1515 document . activeElement ?. dispatchEvent (
@@ -52,7 +52,11 @@ describe("markdown copy without the async clipboard", () => {
5252 expect ( clipboard . execCommand ) . toHaveBeenCalledWith ( "copy" ) ;
5353 } ) ;
5454
55- it ( "copies a table through the execCommand fallback" , async ( ) => {
55+ it . each ( [
56+ [ "no async clipboard" , undefined ] ,
57+ // Firefox before 127 has writeText but no ClipboardItem.
58+ [ "writeText only" , { writeText : ( ) => Promise . resolve ( ) } ] ,
59+ ] ) ( "copies a table through the execCommand fallback with %s" , async ( _ , asyncClipboard ) => {
5660 await using screen = await render (
5761 < MarkdownTable >
5862 < thead >
@@ -69,7 +73,7 @@ describe("markdown copy without the async clipboard", () => {
6973 // The table renders no links and reads no route.
7074 { router : false } ,
7175 ) ;
72- using clipboard = withoutAsyncClipboard ( ) ;
76+ using clipboard = withoutAsyncClipboard ( asyncClipboard ) ;
7377
7478 await userEvent . click ( screen . getByRole ( "button" , { name : "Copy table" } ) ) ;
7579 await userEvent . click ( page . getByRole ( "menuitem" , { name : "Copy as rich text" } ) ) ;
0 commit comments