Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jamuhl committed May 30, 2017
1 parent 9d9db78 commit 606ea26
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,33 @@ const instance = i18n

export default instance
```

### Testing

For testing purpose of your component you should export the pure component without extending with the translate hoc and test that:

```js
export MyComponent;
export default translate('ns')(MyComponent);
```

in the test test the myComponent export passing a t function mock:

```js
import { MyComponent } from './myComponent';

<MyComponent t={key => key} />
```

Or use [https://github.com/kadirahq/react-stubber](https://github.com/kadirahq/react-stubber) to stub i18n functionality:

```js
const tDefault = (key) => key;
const StubbableInterpolate = mayBeStubbed(Interpolate);
const stubInterpolate = function () {
stub(StubbableInterpolate, (props, context) => {
const t = (context && context.t) || tDefault;
return (<span>{t(props.i18nKey)}</span>);
});
};
```

0 comments on commit 606ea26

Please sign in to comment.