Testing server actions containing "revalidatePath" with Jest
Unanswered
West African Lion posted this in #help-forum
West African LionOP
Hello everyone
I'm trying to test a function of my server actions in a jest test to see if the elements I'm testing got correctly inserted in the database.
I managed to get the test running and working, but when I leave my "revalidatePath" call in my function, I got the error
Is there a way to prevent revalidatePath from being called when my function is called from the jest environment ?
I've tried putting
at the top of my test file but it did not work
Here's the content of my jest config file
Here's the versions of my packages
I'm trying to test a function of my server actions in a jest test to see if the elements I'm testing got correctly inserted in the database.
I managed to get the test running and working, but when I leave my "revalidatePath" call in my function, I got the error
Invariant: static generation store missing in revalidateTag Is there a way to prevent revalidatePath from being called when my function is called from the jest environment ?
I've tried putting
/**
* @jest-environment node
*/at the top of my test file but it did not work
Here's the content of my jest config file
const nextJest = require("next/jest");
/** @type {import('jest').Config} */
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
const config = {
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
rootDir: "./",
modulePaths: ["<rootDir>"],
testEnvironment: "node",
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(config);Here's the versions of my packages
"next": "^14.0.4",
"jest": "^29.7.0",