エラー概要
ReactコンポーネントのTestファイルにてエラー発生。
Error: Uncaught [TypeError: Cannot read property 'options' of undefined]
関係しそうなライブラリ
- react (16.8.6)
- typescript (3.4.3)
- i18next (11.3.2)
- react-i18next (7.7.0)
以下のように書き出しているコンポーネントをテストするため、
export default translate()(NavigationHeader);
以下のようにmockを作成しようとしていた。
describe('NavigationHeader', () => {
it('should render', () => {
const wrapperMounted = mount(
<NavigationHeader {...mockNavigationHeaderProps} />
);
// tslint:disable-next-line: no-console
console.log(wrapperMounted.debug());
});
});
そしたらガッツリエラー出ました。
解決法
react-i18nextに関するエラーでした。
i18nConfigが渡されてないためoptions
がないよ、と言われていた模様。
const wrapperMounted = mount(
<I18nextProvider i18n={i18n}>
<NavigationHeader {...mockNavigationHeaderProps} />
</I18nextProvider>
);
こうしたら解決しました。