nuxt-auth-utils icon indicating copy to clipboard operation
nuxt-auth-utils copied to clipboard

How to mock `getUserSession`, `setUserSession`, etc. in end-to-end tests

Open sama305 opened this issue 8 months ago • 0 comments

Hello,

Recently, I have been trying to test an API endpoint for user authentication, but I've been running into an issue with mocking the nuxt-auth-utils functions.

I've tried the following:

mockNuxtImport('getUserSession', () => {
  return {
   //...
  }
})
vi.mock('nuxt-auth-utils', () => ({
  getUserSession: vi.fn(),
  // ....
}))

But nothing has been working. I think it is because getUserSession is a utility function, but I'm not sure. Ideally, I would want to be able to mock the outputs of getusersession and setUserSession on a per test basis. Any help at all is appreciated!

sama305 avatar Jun 17 '25 14:06 sama305