Skip to content

Commit

Permalink
Ensures singular attachment for 3DS container
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissrogers committed Jan 30, 2024
1 parent d77cb71 commit 054cd52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 3 additions & 0 deletions lib/three-d-secure-action.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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 () {
Expand Down
17 changes: 7 additions & 10 deletions test/three-d-secure-action.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,15 @@ describe('<ThreeDSecureAction />', 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(
<ThreeDSecureAction actionTokenId="test-action-token" ref={ref => fixture = ref} />
));

expect(() => getThreeDSecureInstanceFrom(fixture).emit('ready', example)).not.toThrow();
instance.emit('ready');
expect(subject).toHaveBeenCalled();
});
});

Expand Down

0 comments on commit 054cd52

Please sign in to comment.