DethAriel / ng-recaptcha

Angular component for Google reCAPTCHA
https://dethariel.github.io/ng-recaptcha/
MIT License
463 stars 122 forks source link

error unit test with standalone component #286

Closed wfpaisa closed 1 year ago

wfpaisa commented 1 year ago

Summary

I'm submitting a:

Description

Please could you help me to solve this error, I have used this solution using mudules and it works, but in standalone components it does not work.

let reCaptchaV3Service: jasmine.SpyObj<ReCaptchaV3Service>;

describe('@modules/signin/pages - UserComponent', () => {

const reCaptchaV3ServiceSpy = jasmine.createSpyObj(ReCaptchaV3Service, ['execute']);

beforeEach(async () => {
  await TestBed.configureTestingModule({
  imports: [
          RecaptchaV3Module,
  ],
  providers: [
          { provide: RECAPTCHA_V3_SITE_KEY, useValue: environment.captcha },
          { provide: ReCaptchaV3Service, useValue: reCaptchaV3ServiceSpy },
  ]}).compileComponents();
}

  it('should handle captchaGetToken()', fakeAsync(() => {
    reCaptchaV3Service = TestBed.inject(ReCaptchaV3Service) as jasmine.SpyObj<ReCaptchaV3Service>;
    reCaptchaV3Service.execute.and.returnValue(of('123xxx'));

    component.captchaGetToken();
    tick(10);
    expect(reCaptchaV3Service).toHaveBeenCalled();
  }));
image

Thanks :)

DethAriel commented 1 year ago

Hi @wfpaisa ! This seems more like a question around generic jasmine mocks setup, and is thus better suited to a site such as StackOverflow