diff --git a/packages/core/src/payment/strategies/braintree/braintree-hosted-form.spec.ts b/packages/core/src/payment/strategies/braintree/braintree-hosted-form.spec.ts index b723ba083c..f50bcc2083 100644 --- a/packages/core/src/payment/strategies/braintree/braintree-hosted-form.spec.ts +++ b/packages/core/src/payment/strategies/braintree/braintree-hosted-form.spec.ts @@ -206,6 +206,16 @@ describe('BraintreeHostedForm', () => { expect(cardFields.teardown).toHaveBeenCalled(); }); + + it('do not call teardown if fields are not initialized', async () => { + await subject.initialize({ + ...formOptions, + fields: {}, + }); + await subject.deinitialize(); + + expect(cardFields.teardown).not.toHaveBeenCalled(); + }); }); describe('#tokenize', () => { diff --git a/packages/core/src/payment/strategies/braintree/braintree-hosted-form.ts b/packages/core/src/payment/strategies/braintree/braintree-hosted-form.ts index b89fb3e501..5a58ca8d22 100644 --- a/packages/core/src/payment/strategies/braintree/braintree-hosted-form.ts +++ b/packages/core/src/payment/strategies/braintree/braintree-hosted-form.ts @@ -75,9 +75,11 @@ export default class BraintreeHostedForm { } async deinitialize(): Promise { - this._isInitializedHostedForm = false; + if (this._isInitializedHostedForm) { + this._isInitializedHostedForm = false; - await this._cardFields?.teardown(); + await this._cardFields?.teardown(); + } } validate() {