Skip to content

Commit 4422a44

Browse files
committed
test: fix signUp test
1 parent 7288895 commit 4422a44

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

playground-hooks/tests/hooks.spec.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createPage, setup } from '@nuxt/test-utils/e2e'
22
import { expect as playwrightExpect } from '@nuxt/test-utils/playwright'
3-
import { describe, it } from 'vitest'
3+
import { describe, expect, it } from 'vitest'
44

55
const STATUS_AUTHENTICATED = 'authenticated'
66
const 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(/\/api\/auth\/signup/)
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

Comments
 (0)