Last active
July 4, 2024 05:25
-
-
Save codebreach/0a3c5ccfb4e8493cb284f2f5bb844d07 to your computer and use it in GitHub Desktop.
A Stub for Google Recaptcha V3 API. Use it with Cypress to disable recaptcha on client side.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* API Compatible Stub for Google Recaptcha V3. | |
* | |
* Always passes recaptcha checks locally - if this was used in real | |
* life setting then the server side verification would fail. | |
* | |
*/ | |
const requestOptions = []; | |
window.grecaptcha = { | |
ready: callback => callback(), | |
execute: key => { | |
if (requestOptions[key] && requestOptions[key].callback) { | |
requestOptions[key].callback("FAKE_TOKEN"); | |
} | |
return Promise.resolve("FAKE_TOKEN"); | |
}, | |
getResponse: key => { | |
return 1; | |
}, | |
render: (el, options) => { | |
requestOptions.push(options); | |
return requestOptions.length - 1; | |
}, | |
reset: key => {} | |
}; | |
// this should be based on the value passed to api.js?onload=<> | |
// but we hard code it for simplicity | |
ng2recaptchaloaded && ng2recaptchaloaded(window.grecaptcha); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("some test", () => { | |
beforeEach(() => { | |
// to use return recaptcha stub when js is loaded | |
cy.intercept( | |
{ url: /.*\/recaptcha\/api\.js.*/ }, | |
{ | |
fixture: "stub-recaptcha-api.js,null" | |
} | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why this is not working?
(uncaught exception)ReferenceError: ng2recaptchaloaded is not defined