use-recaptcha.spec.tsx 996 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { useRecaptcha } from '@/shared/hooks/use-recaptcha'
  2. import * as ReactGoogleRecaptcha from 'react-google-recaptcha'
  3. const ReCaptcha = () => {
  4. const { ref: recaptchaRef, getReCaptchaToken } = useRecaptcha()
  5. const handleClick = async () => {
  6. await getReCaptchaToken()
  7. }
  8. return (
  9. <>
  10. <ReactGoogleRecaptcha.ReCAPTCHA
  11. ref={recaptchaRef}
  12. size="invisible"
  13. sitekey="123456"
  14. badge="inline"
  15. />
  16. <button onClick={handleClick}>Click</button>
  17. </>
  18. )
  19. }
  20. describe('useRecaptcha', function () {
  21. it('should reset the captcha', function () {
  22. cy.spy(ReactGoogleRecaptcha.ReCAPTCHA.prototype, 'reset').as('resetSpy')
  23. cy.spy(ReactGoogleRecaptcha.ReCAPTCHA.prototype, 'executeAsync').as(
  24. 'executeAsyncSpy'
  25. )
  26. cy.mount(<ReCaptcha />)
  27. cy.findByRole('button', { name: /click/i }).click()
  28. cy.get('@resetSpy').should('have.been.calledOnce')
  29. cy.get('@executeAsyncSpy').should('have.been.calledOnce')
  30. })
  31. })