How to I get a valid session from a jest script? #2397
Unanswered
shreyas-jadhav
asked this question in
Help
Replies: 1 comment
-
Hi, if interested, I wrote a package for mocking next-auth like: import { render, screen } from '@testing-library/react'
import { withMockAuth } from '@tomfreudenberg/next-auth-mock/jest';
import SignoutPage from '@/pages/auth/signoutx';
describe('Pages', () => {
describe('Signout', () => {
it('should render want to sign out', () => {
render(withMockAuth(<SignoutPage />, 'userAuthed'));
expect(screen.getByText('Do you want to sign out?'));
});
});
}); Find the whole story at: https://github.com/TomFreudenberg/next-auth-mock |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question 💬
I was trying to test my APIs with Jest, wondering if it's possible to sign in and get a valid session from a jest script.
I hoping if it can be possible without sign in method. because if i use
@jest-environment jsdom
I can run the sign in method but I don't get to pass the absolute URL.for example the auth url is
https://localhost:3000/auth
but as I'm using node fetch. (because the normal fetch is not available) the URL becomes relative in the signIn method. that is it becomes
/auth
and i get an error. let me know if there can be a better way to get a valid session from a server environment..How to reproduce ☕️
Contributing 🙌🏽
No, I am afraid I cannot help regarding this
Beta Was this translation helpful? Give feedback.
All reactions