nuxt-auth-utils
nuxt-auth-utils copied to clipboard
How to mock `getUserSession`, `setUserSession`, etc. in end-to-end tests
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!