@@ -88,6 +88,70 @@ describe("ReCAPTCHA", () => {
8888 instance . _internalRef . current . execute ( ) ;
8989 expect ( grecaptchaMock . execute ) . toBeCalledWith ( WIDGET_ID ) ;
9090 } ) ;
91+ it ( "executeAsync, should call grecaptcha.execute with the widget id" , ( ) => {
92+ const WIDGET_ID = "someWidgetId" ;
93+ const grecaptchaMock = {
94+ render ( ) {
95+ return WIDGET_ID ;
96+ } ,
97+ execute : jest . fn ( ) ,
98+ } ;
99+ // wrapping component example that applies a ref to ReCAPTCHA
100+ class WrappingComponent extends React . Component {
101+ constructor ( props ) {
102+ super ( props ) ;
103+ this . _internalRef = React . createRef ( ) ;
104+ }
105+ render ( ) {
106+ return (
107+ < div >
108+ < ReCAPTCHA
109+ sitekey = "xxx"
110+ size = "invisible"
111+ grecaptcha = { grecaptchaMock }
112+ onChange = { jest . fn ( ) }
113+ ref = { this . _internalRef }
114+ />
115+ </ div >
116+ ) ;
117+ }
118+ }
119+ const instance = ReactTestUtils . renderIntoDocument ( React . createElement ( WrappingComponent ) ) ;
120+ instance . _internalRef . current . execute ( ) ;
121+ expect ( grecaptchaMock . execute ) . toBeCalledWith ( WIDGET_ID ) ;
122+ } ) ;
123+ it ( "executeAsync, should return a promise" , ( ) => {
124+ const WIDGET_ID = "someWidgetId" ;
125+ const grecaptchaMock = {
126+ render ( ) {
127+ return WIDGET_ID ;
128+ } ,
129+ execute : jest . fn ( ) ,
130+ } ;
131+ // wrapping component example that applies a ref to ReCAPTCHA
132+ class WrappingComponent extends React . Component {
133+ constructor ( props ) {
134+ super ( props ) ;
135+ this . _internalRef = React . createRef ( ) ;
136+ }
137+ render ( ) {
138+ return (
139+ < div >
140+ < ReCAPTCHA
141+ sitekey = "xxx"
142+ size = "invisible"
143+ grecaptcha = { grecaptchaMock }
144+ onChange = { jest . fn ( ) }
145+ ref = { this . _internalRef }
146+ />
147+ </ div >
148+ ) ;
149+ }
150+ }
151+ const instance = ReactTestUtils . renderIntoDocument ( React . createElement ( WrappingComponent ) ) ;
152+ let result = instance . _internalRef . current . executeAsync ( ) ;
153+ expect ( result ) . toBeInstanceOf ( Promise ) ;
154+ } ) ;
91155 describe ( "Expired" , ( ) => {
92156 it ( "should call onChange with null when response is expired" , ( ) => {
93157 const WIDGET_ID = "someWidgetId" ;
0 commit comments