11import { createPage , setup } from '@nuxt/test-utils/e2e'
22import { expect as playwrightExpect } from '@nuxt/test-utils/playwright'
3- import { describe , it } from 'vitest'
3+ import { describe , expect , it } from 'vitest'
44
55const STATUS_AUTHENTICATED = 'authenticated'
66const STATUS_UNAUTHENTICATED = 'unauthenticated'
@@ -78,6 +78,15 @@ describe('local Provider', async () => {
7878 await usernameInput . fill ( 'newuser' )
7979 await passwordInput . fill ( 'hunter2' )
8080
81+ // Test `preventLoginFlow`
82+ let loginCalled = false
83+
84+ page . on ( 'request' , request => {
85+ if ( request . url ( ) . includes ( '/api/auth/login' ) ) {
86+ loginCalled = true
87+ }
88+ } )
89+
8190 // Click button and wait for API to finish
8291 const responsePromise = page . waitForResponse ( / \/ a p i \/ a u t h \/ s i g n u p / )
8392 await submitButton . click ( )
@@ -87,7 +96,16 @@ describe('local Provider', async () => {
8796 const responseBody = await response . json ( ) // Parse response
8897 playwrightExpect ( responseBody ) . toBeDefined ( ) // Ensure data is returned
8998
90- // Since we use `preventLoginFlow`, status should be unauthenticated
91- await playwrightExpect ( status ) . toHaveText ( STATUS_UNAUTHENTICATED )
99+ // Note: even though we use `preventLoginFlow` and logically
100+ // one may assume that status should be unauthenticated,
101+ // the demo signUp endpoint returns the signed in user,
102+ // and the adapter hook picks it up, automatically signing the user in
103+ // without an extra call to `signIn`. We therefore test this
104+ // in a different way by checking that `/api/auth/login` was not called.
105+ await playwrightExpect ( status ) . toHaveText ( STATUS_AUTHENTICATED )
106+
107+ // Wait long enough for all network activity to settle
108+ await page . waitForTimeout ( 500 )
109+ expect ( loginCalled ) . toBe ( false )
92110 } )
93111} )
0 commit comments