Skip to content

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

@sama305

Description

@sama305

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions