From 054cd52e0da57e63ef07516d43973298ba1ded8c Mon Sep 17 00:00:00 2001 From: Christopher Rogers Date: Mon, 29 Jan 2024 12:49:01 -0800 Subject: [PATCH] Ensures singular attachment for 3DS container --- lib/three-d-secure-action.jsx | 3 +++ test/three-d-secure-action.test.jsx | 17 +++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/three-d-secure-action.jsx b/lib/three-d-secure-action.jsx index f9a8d06..37bfc40 100644 --- a/lib/three-d-secure-action.jsx +++ b/lib/three-d-secure-action.jsx @@ -73,6 +73,7 @@ export default class ThreeDSecureAction extends React.PureComponent { const { actionTokenId } = props; + this._attached = false; this._container = React.createRef(); this._risk = this.context.recurly.Risk(); this._threeDSecure = this._risk.ThreeDSecure({ actionTokenId }); @@ -82,7 +83,9 @@ export default class ThreeDSecureAction extends React.PureComponent { } componentDidMount () { + if (this._attached) return; this._threeDSecure.attach(this._container.current); + this._attached = true; } render () { diff --git a/test/three-d-secure-action.test.jsx b/test/three-d-secure-action.test.jsx index 60d8ee1..d4d0928 100644 --- a/test/three-d-secure-action.test.jsx +++ b/test/three-d-secure-action.test.jsx @@ -58,18 +58,15 @@ describe('', function () { /> )); - getThreeDSecureInstanceFrom(fixture).emit('ready', ); - expect(subject).toHaveBeenCalled(); - }); + const instance = getThreeDSecureInstanceFrom(fixture); - it('does nothing when no handler is provided', function () { - let fixture; + // stub strategy so that the readiness chain will not fall apart + instance.strategy = { + attach: () => {} + }; - render(withRecurlyProvider( - fixture = ref} /> - )); - - expect(() => getThreeDSecureInstanceFrom(fixture).emit('ready', example)).not.toThrow(); + instance.emit('ready'); + expect(subject).toHaveBeenCalled(); }); });