Next.js Discord

Discord Forum

Test suite failed to run TypeError: (0 , _local.default) is not a function using 'next/font/local'

Answered
Cape horse mackerel posted this in #help-forum
Open in Discord
Cape horse mackerelOP
Test suite failed to run TypeError: (0 , _local.default) is not a function - Have you seen this error or have any ideas for resolving it? I'm using localFont from 'next/font/local' for font handling purposes. All works fine during normal execution, but in test, I get the error below. Here is the rest of the error message;
90 | export const Syne = localFont({
| ^
91 | src: '../../../../../styles/fonts/syne/files/syne-latin-wght-normal.woff2',
92 | display: 'swap',
93 | weight: '100 900',
at Object.<anonymous> (../../libs/web/ui/theme/src/DefaultMediaSiteTheme.ts:90:30)
at Object.<anonymous> (../../libs/web/ui/theme/src/index.ts:3:1)
at Object.<anonymous> (../../libs/web/ui/logo/src/Logo.tsx:6:1)
at Object.<anonymous> (../../libs/web/ui/logo/src/index.ts:3:1)
at Object.<anonymous> (pages/index.tsx:5:1)
at Object.<anonymous> (specs/index.spec.tsx:5:1)
Any thoughts/suggestions are greatly appreciated! (edited)
Answered by Cape horse mackerel
Here's how I eventually resolved this issue in my particular case: /* A mock for the function, localFont(). */ jest.mock("next/font/local", () => function() { return { style: { fontFamily: 'my_font' } } } );
View full answer

1 Reply

Cape horse mackerelOP
Here's how I eventually resolved this issue in my particular case: /* A mock for the function, localFont(). */ jest.mock("next/font/local", () => function() { return { style: { fontFamily: 'my_font' } } } );
Answer