-
I'm having difficulties testing its middleware. Usually when I write the tests of something, it has functions I can mock and test if they were just called with our without certain value. In the case of next-auth, I'd like to test the signIn callback, but:
Promise {
<pending>,
[Symbol(async_id_symbol)]: 121983,
[Symbol(trigger_async_id_symbol)]: 121973,
[Symbol(destroyed)]: { destroyed: false }
} Oh, it's a promise, it makes sense to undefined Even its function return type is Useful link of it being tested with Cypress: https://next-auth.js.org/tutorials/testing-with-cypress I think Cypress is used for E2E tests which we don't have yet I think. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
FYI When struggling with I don't think we need to test the return value of nextauth middleware, but rather what we pass into nextauth right via the callbacks? If so, we just need to test the callback functions. Example (about signInCallback) export const signInCallback = async ({ user, account, profile, email, credentials }) {
...
}
...
callbacks: {
signIn: signinCallback,
...
...
} In your test you'd just test |
Beta Was this translation helpful? Give feedback.
FYI When struggling with
unit
test, the correct solution isn't "let's add functional test". It works, but it hides the underlying problem which is that we want to figure out a way to unit test the function.I don't think we need to test the return value of nextauth middleware, but rather what we pass into nextauth right via the callbacks? If so, we just need to test the callback functions.
Example (about signInCallback)
In your test you'd just test
signInCallback
right?