React-i18next: Failing tests in react_withHOC

Created on 31 Oct 2017  ·  4Comments  ·  Source: i18next/react-i18next

After following the example in react_withHOC, I've found the following error. At first I assumed it was an issue in my code, but it appears that it is also an issue in the example folder in this repo.

$ npm test

FAIL  src/App.test.js
  ● renders without crashing

    TypeError: Cannot read property 'options' of undefined

      at new I18n (node_modules/react-i18next/dist/commonjs/I18n.js:54:20)
      at constructClassInstance (node_modules/react-dom/cjs/react-dom.development.js:9760:20)
      at updateClassComponent (node_modules/react-dom/cjs/react-dom.development.js:10215:9)
      at beginWork (node_modules/react-dom/cjs/react-dom.development.js:10605:16)
      at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:12573:16)
      at workLoop (node_modules/react-dom/cjs/react-dom.development.js:12682:28)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:1299:14)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:219:27)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:126:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:36:27)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:61:35)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:1338:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:1195:27)
      at performWork (node_modules/react-dom/cjs/react-dom.development.js:12800:7)
      at scheduleUpdateImpl (node_modules/react-dom/cjs/react-dom.development.js:13185:19)
      at scheduleUpdate (node_modules/react-dom/cjs/react-dom.development.js:13124:12)
      at scheduleTopLevelUpdate (node_modules/react-dom/cjs/react-dom.development.js:13395:5)
      at Object.updateContainer (node_modules/react-dom/cjs/react-dom.development.js:13425:7)
      at node_modules/react-dom/cjs/react-dom.development.js:17105:19
      at Object.unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:13256:14)
      at renderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:17104:17)
      at Object.render (node_modules/react-dom/cjs/react-dom.development.js:17129:12)
      at Object.<anonymous>.it (src/App.test.js:7:22)
          at new Promise (<anonymous>)
      at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

  ✕ renders without crashing (13ms)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        5.189s
Ran all test suites.

  console.error node_modules/fbjs/lib/warning.js:33
    Warning: React depends on requestAnimationFrame. Make sure that you load a polyfill in older browsers. http://fb.me/react-polyfills

  console.error node_modules/react-dom/cjs/react-dom.development.js:8305
    The above error occurred in the <I18n> component:
        in I18n (created by Translate(App))
        in Translate(App) (at App.test.js:7)

    Consider adding an error boundary to your tree to customize error handling behavior.
    You can learn more about error boundaries at https://fb.me/react-error-boundaries.

Most helpful comment

Honestly more lies in the fact i never touched the test file...https://github.com/i18next/react-i18next/blob/master/example/react_withHOC/src/App.test.js#L7

that needs to be wrapped or import i18n like: https://github.com/i18next/react-i18next/blob/master/example/react_withHOC/src/index.js#L7 else there won't be an i18n instance set to context or react-i18next internal context

All 4 comments

are you sure...looks like the sample runs at my computer...

https://github.com/i18next/react-i18next/blob/master/src/I18n.js#L28

looks like the i18n instance is not set, either using the provider or i18next.use(reactI18nextModule)

After running npm test, I entered "a" so that react-scripts would run all the tests. This is when it would fail for me. And on CI, that runs every time, so tests are never passing for me. Can you replicate this using "a"?

Honestly more lies in the fact i never touched the test file...https://github.com/i18next/react-i18next/blob/master/example/react_withHOC/src/App.test.js#L7

that needs to be wrapped or import i18n like: https://github.com/i18next/react-i18next/blob/master/example/react_withHOC/src/index.js#L7 else there won't be an i18n instance set to context or react-i18next internal context

That makes total sense, what a simple fix! I PR'd a fix for this too 👌

It should auto-close this issue on-merge because of the "fixes" keyword in the PR title. Thanks for such fast responses on everything, it's making this library much more of a pleasure for us to use.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicholasmaddren picture nicholasmaddren  ·  4Comments

aniket-dalvi picture aniket-dalvi  ·  4Comments

ChCosmin picture ChCosmin  ·  4Comments

pwiszowaty0 picture pwiszowaty0  ·  4Comments

ok2ju picture ok2ju  ·  3Comments