@@ -120,13 +120,17 @@ describe("ReCAPTCHA", () => {
120120 instance . _internalRef . current . executeAsync ( ) ;
121121 expect ( grecaptchaMock . execute ) . toBeCalledWith ( WIDGET_ID ) ;
122122 } ) ;
123- it ( "executeAsync, should return a promise" , ( ) => {
123+ it ( "executeAsync, should return a promise that resolves with the token " , ( ) => {
124124 const WIDGET_ID = "someWidgetId" ;
125+ const TOKEN = "someToken" ;
125126 const grecaptchaMock = {
126- render ( ) {
127+ render ( _ , { callback } ) {
128+ this . callback = callback ;
127129 return WIDGET_ID ;
128130 } ,
129- execute : jest . fn ( ) ,
131+ execute ( ) {
132+ this . callback ( TOKEN ) ;
133+ } ,
130134 } ;
131135 // wrapping component example that applies a ref to ReCAPTCHA
132136 class WrappingComponent extends React . Component {
@@ -149,8 +153,11 @@ describe("ReCAPTCHA", () => {
149153 }
150154 }
151155 const instance = ReactTestUtils . renderIntoDocument ( React . createElement ( WrappingComponent ) ) ;
152- let result = instance . _internalRef . current . executeAsync ( ) ;
153- expect ( result ) . toBeInstanceOf ( Promise ) ;
156+ const executeAsyncDirectValue = instance . _internalRef . current . executeAsync ( ) ;
157+ expect ( executeAsyncDirectValue ) . toBeInstanceOf ( Promise ) ;
158+ return executeAsyncDirectValue . then ( executeAsyncResolveValue => {
159+ expect ( executeAsyncResolveValue ) . toBe ( TOKEN ) ;
160+ } ) ;
154161 } ) ;
155162 describe ( "Expired" , ( ) => {
156163 it ( "should call onChange with null when response is expired" , ( ) => {
0 commit comments