Skip to content

Commit

Permalink
Merge pull request #853 from naholyr/feat/expose-wrapped-component
Browse files Browse the repository at this point in the history
HOC: expose wrapped component as WrappedComponent property
  • Loading branch information
jamuhl committed May 21, 2019
2 parents 58d508b + 64a5ded commit 7481688
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/withSSR.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function withSSR() {

I18nextWithSSR.getInitialProps = composeInitialProps(WrappedComponent);
I18nextWithSSR.displayName = `withI18nextSSR(${getDisplayName(WrappedComponent)})`;
I18nextWithSSR.WrappedComponent = WrappedComponent;

return I18nextWithSSR;
};
Expand Down
3 changes: 3 additions & 0 deletions src/withTranslation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export function withTranslation(ns, options = {}) {
I18nextWithTranslation.displayName = `withI18nextTranslation(${getDisplayName(
WrappedComponent,
)})`;

I18nextWithTranslation.WrappedComponent = WrappedComponent;

return options.withRef ? React.forwardRef(I18nextWithTranslation) : I18nextWithTranslation;
};
}
5 changes: 5 additions & 0 deletions test/withSSR.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ describe('withSSR', () => {
setI18n(i18n);
});

it('should export wrapped component', () => {
const HocElement = withSSR()(TestComponent);
expect(HocElement.WrappedComponent).toBe(TestComponent);
});

it('should set values', () => {
const HocElement = withSSR()(TestComponent);
const wrapper = mount(<HocElement initialI18nStore={{ foo: 'bar' }} initialLanguage="de" />);
Expand Down
5 changes: 5 additions & 0 deletions test/withTranslation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ describe('withTranslation', () => {
return <div>{t('key1')}</div>;
}

it('should export wrapped component', () => {
const HocElement = withTranslation()(TestComponent);
expect(HocElement.WrappedComponent).toBe(TestComponent);
});

it('should render correct content', () => {
const HocElement = withTranslation()(TestComponent);
const wrapper = mount(<HocElement />);
Expand Down

0 comments on commit 7481688

Please sign in to comment.