Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Commit

Permalink
register all elements (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
dweedon-stripe authored Apr 21, 2020
1 parent bcd8f80 commit 809258a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 5 additions & 11 deletions src/components/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,12 @@ const Element = (
element.mount(this._ref);

// Register Element for automatic token / source / paymentMethod creation
if (
hocOptions.impliedTokenType ||
hocOptions.impliedSourceType ||
this.context.registerElement(
element,
hocOptions.impliedTokenType,
hocOptions.impliedSourceType,
hocOptions.impliedPaymentMethodType
) {
this.context.registerElement(
element,
hocOptions.impliedTokenType,
hocOptions.impliedSourceType,
hocOptions.impliedPaymentMethodType
);
}
);
});
}

Expand Down
10 changes: 8 additions & 2 deletions src/components/Element.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ describe('Element', () => {
expect(context.unregisterElement).toHaveBeenCalledWith(elementMock);
});

it('should call the right hooks for a non-registered Element', () => {
it('should call the right hooks for a non-auto-detected Element', () => {
const TestElement = Element('test');
const element = mount(<TestElement onChange={jest.fn()} />, {context});

expect(context.registerElement).toHaveBeenCalledTimes(0);
expect(context.registerElement).toHaveBeenCalledTimes(1);
expect(context.registerElement).toHaveBeenCalledWith(
elementMock,
undefined,
undefined,
undefined
);

element.unmount();
expect(elementMock.destroy).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit 809258a

Please sign in to comment.