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

register all elements #519

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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