I'm building a Next.JS app with typescript and testing with Jest and testing-library/react, and I'm noticing that Jest is failing to find getBackendOptions as a module export. It catches the following error:
TypeError: (0 , _reactdndtreeview.getBackendOptions) is not a function
16 | return (
17 | <div className="app">
> 18 | <DndProvider backend={MultiBackend} options={getBackendOptions()}>
| ^
19 | <Tree
20 | tree={treeData}
21 | rootId={0}
at NavTree (src/views/khub/nav-tree.test.tsx:18:69)
To Reproduce
Using the minimal configuration example from storybook:
I also had to install a couple cjs packages and modify my Jest config:
// jest.config.mjs
import nextJest from "next/jest.js";
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
});
// Add any custom config to be passed to Jest
/** @type {import('jest').Config} */
const config = {
// Add more setup options before each test is run
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
testEnvironment: "jest-environment-jsdom",
moduleNameMapper: {
"^.+\\.(svg)$": "<rootDir>/src/mocks/svg.jsx",
"react-markdown":
"<rootDir>/node_modules/react-markdown/react-markdown.min.js",
"react-dnd": "react-dnd-cjs",
"react-dnd-html5-backend": "react-dnd-html5-backend-cjs",
"react-dnd-touch-backend": "react-dnd-touch-backend-cjs",
},
collectCoverageFrom: ["src/**/*.{js,jsx,ts,tsx}", "!src/**/*.d.ts"],
coverageReporters: ["text", "html", "cobertura"],
coverageThreshold: {
global: {
statements: 77,
branches: 67,
functions: 65,
lines: 77,
},
},
snapshotSerializers: ["@emotion/jest/serializer"],
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config);
Expected behavior
I expect the module exports to be in sync with what I see in dist/index.js but when I put the following in the test
I'm building a Next.JS app with typescript and testing with Jest and
testing-library/react
, and I'm noticing that Jest is failing to findgetBackendOptions
as a module export. It catches the following error:To Reproduce Using the minimal configuration example from storybook:
I also had to install a couple
cjs
packages and modify my Jest config:Expected behavior I expect the module exports to be in sync with what I see in
dist/index.js
but when I put the following in the testI see:
Desktop (please complete the following information):
Additional context Here's my package.json: