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();
});
});