Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How to use $app/navigation inside the vitest unit test

$
0
0

Getting this error in files where I am using $app/navigation:Error: Failed to resolve import "$app/navigation" from "src/utils/navigationUtils.js". Does the file exist?.

Here is my setupTests.js file but now getting the same error in this file.

import "@testing-library/jest-dom";import { vi } from "vitest";import * as navigation from "$app/navigation";// Mock SvelteKit runtime module $app/navigationvi.mock("$app/navigation", () => ({  afterNavigate: () => {},  beforeNavigate: () => {},  disableScrollHandling: () => {},  goto: () => Promise.resolve(),  invalidate: () => Promise.resolve(),  invalidateAll: () => Promise.resolve(),  prefetch: () => Promise.resolve(),  prefetchRoutes: () => Promise.resolve(),}));

After this configration now getting:Error: Failed to resolve import "$app/navigation" from "setupTests.js". Does the file exist?

I have tried to mock the $app/navigation module in setupTests.js file but no success.


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>