'Jest test doesn't work with svelte-routing navigate()

I'm using svelte and svelte-routing for my SPA.

In App.svelte I call navigate() in the onMount() :

onMount(async() => {
    if ($isLogged) {
      navigate('/dashboard')
    } else {
      navigate('/')
    }
  });

When I launch my test with Jest I've got this error:

node:internal/process/promises:265
triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TypeError: Cannot read properties of undefined (reading 'substr')".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Does someone has already faced this issue ?

Thanks for your help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source