File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -165,6 +165,48 @@ test.describe("API Methods", () => {
165165 } ) ;
166166 expect ( success ) . toBe ( true ) ;
167167 } ) ;
168+
169+ test ( "preserves a getContent callback passed to setOptions" , async ( { reactGrab } ) => {
170+ const result = await reactGrab . page . evaluate ( async ( ) => {
171+ const api = (
172+ window as {
173+ __REACT_GRAB__ ?: {
174+ copyElement : ( element : Element ) => Promise < boolean > ;
175+ setOptions : ( options : { getContent : ( ) => string } ) => void ;
176+ } ;
177+ }
178+ ) . __REACT_GRAB__ ;
179+ const element = document . querySelector ( "[data-testid='todo-list'] h1" ) ;
180+ if ( ! api || ! element ) throw new Error ( "React Grab API or test element unavailable" ) ;
181+
182+ let getContentCallCount = 0 ;
183+ api . setOptions ( {
184+ getContent : ( ) => {
185+ getContentCallCount += 1 ;
186+ return "custom content" ;
187+ } ,
188+ } ) ;
189+ const callCountBeforeCopy = getContentCallCount ;
190+ const originalExecCommand = document . execCommand ;
191+ document . execCommand = ( ) => true ;
192+
193+ try {
194+ return {
195+ callCountBeforeCopy,
196+ didCopy : await api . copyElement ( element ) ,
197+ getContentCallCount,
198+ } ;
199+ } finally {
200+ document . execCommand = originalExecCommand ;
201+ }
202+ } ) ;
203+
204+ expect ( result ) . toEqual ( {
205+ callCountBeforeCopy : 0 ,
206+ didCopy : true ,
207+ getContentCallCount : 1 ,
208+ } ) ;
209+ } ) ;
168210 } ) ;
169211
170212 test . describe ( "Theme via setOptions" , ( ) => {
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ const createPluginRegistry = (initialOptions: SettableOptions = {}) => {
102102 optionValue : OptionsState [ OptionKey ] ,
103103 ) => {
104104 directOptionOverrides [ optionKey ] = optionValue ;
105- setStore ( "options" , optionKey , optionValue ) ;
105+ setStore ( "options" , optionKey , ( ) => optionValue ) ;
106106 } ;
107107
108108 const SETTABLE_OPTION_KEYS : Array < keyof OptionsState > = [
You can’t perform that action at this time.
0 commit comments