Unable to run localFont()
in jest: (0 , local_1.default) is not a function
#55616
Labels
bug
Issue was opened via the bug report template.
Font (next/font)
Related to Next.js Font Optimization.
Link to the code that reproduces this issue
https://github.com/arthur-zhao-anrok/next_bug_repro_repo
To Reproduce
cd reproduction-app/
npm install
npm run test
Current vs. Expected behavior
Current behavior: the test errs out with the following error:
Expected behavior: the test should run successfully.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000 Binaries: Node: 18.8.0 npm: 8.18.0 Yarn: 4.0.0-rc.38 pnpm: N/A Relevant Packages: next: 13.5.1-canary.1 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Font optimization (next/font)
Additional context
I tested my reproduction against both the canary release and v13.4.10.
In my actual production project, I used
localFont()
in a module calledtheme.ts
that is used by multiple frontend components. It works well in production when those frontend components were used as part of the Next.js frontend app.However, when I used Jest to test the modules that relies on
theme.ts
, the tests would err out when importing those modules. I ended up mockingnext/font/local
to circumvent the issue.Similar issue on StackOverflow: https://stackoverflow.com/questions/76659367/typeerror-0-local-default-is-not-a-function-when-using-next-font-local-in-j
The text was updated successfully, but these errors were encountered: