angular2-recaptcha icon indicating copy to clipboard operation
angular2-recaptcha copied to clipboard

Google recaptcha lib is loaded more than once in unit tests

Open aacanakin opened this issue 8 years ago • 3 comments

I have a wrapper around captcha component. The captcha component is imported in custom module namely UiModule. When I run unit tests, I have the following error;

Uncaught Error: ReCAPTCHA placeholder element must be empty

I checked this error. This error originates from loading google captcha library more than once. Here's the beforeEach function of wrapper component;

beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        UiModule
      ]
    }).compileComponents();
  }));

beforeEach(() => {

    fixture = TestBed.createComponent(CaptchaComponent);
    component = fixture.componentInstance;

    component.token = environment.captcha.testToken;
    component.siteKey = environment.captcha.siteKey;
    component.testMode = true;

    fixture.detectChanges();
  });

UiModule declaration has RecaptchaModule exports.

aacanakin avatar Jun 01 '17 14:06 aacanakin

Do you have a solution in mind?

xmaestro avatar Jun 05 '17 08:06 xmaestro

I don't have any solution currently. Maybe, the component would unload google recaptcha lib after its ngOnDestroy hook is called? Is it possible @xmaestro ?

aacanakin avatar Jun 05 '17 13:06 aacanakin

Were you able to find a workaround?

xmaestro avatar Aug 01 '17 11:08 xmaestro