Skip to content

Commit 563bcb4

Browse files
committed
#795 Fix tests
1 parent 7738ae7 commit 563bcb4

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

test/unit/login/login.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest'
2-
import { authn, authSession, solidLogicSingleton } from 'solid-logic'
32
import * as testLogin from '../../../src/login/login'
43

54
describe('ensureLoggedIn', () => {
@@ -20,24 +19,25 @@ describe('getUserRoles', () => {
2019
})
2120

2221
it('returns [] and does not load preferences when current user is missing', async () => {
23-
vi.spyOn(authSession, 'info', 'get').mockReturnValue({
22+
vi.resetModules()
23+
24+
const { authn, authSession, solidLogicSingleton } = await import('solid-logic')
25+
26+
authSession.info = {
2427
isLoggedIn: true,
25-
webId: 'https://alice.example.com/profile/card#me',
26-
sessionId: 'test-session'
27-
})
28+
webId: 'https://alice.example.com/profile/card#me'
29+
}
2830

29-
const currentUserSpy = vi
30-
.spyOn(authn, 'currentUser')
31-
.mockReturnValue(null)
32-
const loadPreferencesSpy = vi.spyOn(
33-
solidLogicSingleton.profile,
34-
'loadPreferences'
35-
)
31+
vi.spyOn(authn, 'checkUser').mockResolvedValue(null)
3632

37-
const roles = await testLogin.getUserRoles()
33+
const currentUserSpy = vi.spyOn(authn, 'currentUser').mockReturnValue(null)
34+
const loadPreferencesSpy = vi.spyOn(solidLogicSingleton.profile, 'loadPreferences')
35+
36+
const { getUserRoles } = await import('../../../src/login/login')
37+
const roles = await getUserRoles()
3838

39-
expect(currentUserSpy).toHaveBeenCalled()
4039
expect(roles).toEqual([])
40+
expect(currentUserSpy).toHaveBeenCalled()
4141
expect(loadPreferencesSpy).not.toHaveBeenCalled()
4242
})
4343
})

vite.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ function defaultConfig(): UserConfig {
6666
test: {
6767
environment: 'jsdom',
6868
setupFiles: ['test/helpers/setup.ts'],
69+
include: [
70+
'src/**/*.test.ts',
71+
'test/**/*.test.ts',
72+
],
6973
coverage: {
7074
include: ['src/**/*.[jt]s'],
7175
},

0 commit comments

Comments
 (0)