Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

When importing i18n in my setupTest file I get TypeError: Cannot destructure property 'config' of 'cacheKeyOptions' as it is undefined #1569

Closed
alveshelio opened this issue Oct 27, 2022 · 2 comments

Comments

@alveshelio
Copy link

馃悰 Bug Report

I'm using react-i18next in my App and I have not issues with the translations. However, when doing tests following this guide: https://react.i18next.com/misc/testing#testing-without-stubbing.

I'm getting an error: TypeError: Cannot destructure property 'config' of 'cacheKeyOptions' as it is undefined.
I've searched for this type of error and found these two issues:
https://sebastian-rogers.medium.com/cannot-destructure-property-config-of-cachekeyoptions-as-it-is-undefined-f31b383abf5c
callstack/react-native-testing-library#743

However, both of them are saying that it's simply because Jest is outdated. This is not my case since I'm running the latest version of Jest at the moment which is 29.2.2. I'm also using ts-jest and it too is up to date, version 29.0.3

I've tried the other approaches that suggest to mock useTranslations hook, however, this does not work for me since I need to have the translations in the code and not only the translation keys.

I've deleted most of my translations files, in public/locales/en I only have one file for the example but in my project I have a bunch of them.

This is a Create React App V4 that I've ejected.

To Reproduce

Here's a codesandbox example

// Paste your code here

Expected behavior

I would expect Jest to be able to import the i18next instance to provide translations in my tests

Your Environment

  • runtime version: i.e. node v16.17.0
  • i18next: "^21.6.14",
  • i18next-http-backend: "^1.3.1",
  • i18next-parser: "^6.4.0",
  • react-i18next: "^11.16.2",
  • os: Linux Ubuntu 20
@adrai
Copy link
Member

adrai commented Oct 27, 2022

sorry, no idea.... (looks to be out of i18next scope)
you may try to create a minimum reproducible example...
just the most necessary parts to reproduce the issue

@alveshelio
Copy link
Author

Hi Adira,

Thank you for getting back, indeed, the problem isn't with i18next, it was with Jest. In case someone ends up with the same issue as me here's what was happening.

I have a project in Typescript but some config files are in JavaScript and Jest needs to load these config files. I'm using ts-jest to transform Typescript files but I was missing babel-jest to transform JavaScript files.

The I only needed to add '^.+\\.js$': 'babel-jest', to transform and it fixed my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants