1- /**
1+ /*!
22 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
33 * SPDX-License-Identifier: GPL-3.0-or-later
44 */
5- import { describe , it , expect , vi , beforeEach , afterEach } from 'vitest'
5+
66import { getBuilder } from '@nextcloud/browser-storage'
77import { emit } from '@nextcloud/event-bus'
8+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
89
910// Mock dependencies
1011vi . mock ( '@nextcloud/browser-storage' )
@@ -20,7 +21,7 @@ const mockBrowserStorage = {
2021}
2122
2223// Mock crypto for UUID generation
23- const originalCrypto = global . crypto
24+ const originalCrypto = globalThis . crypto
2425const mockCrypto = {
2526 randomUUID : vi . fn ( ( ) => 'mock-uuid-' + Math . random ( ) . toString ( 36 ) . slice ( 2 , 10 ) ) ,
2627}
@@ -42,16 +43,16 @@ describe('Guest User Module', () => {
4243 } ) ,
4344 } )
4445
45- // Replace global crypto with mock
46- Object . defineProperty ( global , 'crypto' , {
46+ // Replace globalThis crypto with mock
47+ Object . defineProperty ( globalThis , 'crypto' , {
4748 value : mockCrypto ,
4849 writable : true ,
4950 } )
5051 } )
5152
5253 afterEach ( ( ) => {
5354 // Restore original crypto
54- Object . defineProperty ( global , 'crypto' , {
55+ Object . defineProperty ( globalThis , 'crypto' , {
5556 value : originalCrypto ,
5657 writable : true ,
5758 } )
@@ -122,12 +123,8 @@ describe('Guest User Module', () => {
122123 describe ( 'setGuestNickname' , ( ) => {
123124 it ( 'should throw an error if nickname is empty' , async ( ) => {
124125 const { setGuestNickname } = await import ( '../lib' )
125- expect ( ( ) => setGuestNickname ( '' ) ) . toThrow (
126- 'Nickname cannot be empty' ,
127- )
128- expect ( ( ) => setGuestNickname ( ' ' ) ) . toThrow (
129- 'Nickname cannot be empty' ,
130- )
126+ expect ( ( ) => setGuestNickname ( '' ) ) . toThrow ( 'Nickname cannot be empty' )
127+ expect ( ( ) => setGuestNickname ( ' ' ) ) . toThrow ( 'Nickname cannot be empty' )
131128 } )
132129
133130 it ( 'should set the nickname and store it in browser storage' , async ( ) => {
@@ -162,7 +159,6 @@ describe('Guest User Module', () => {
162159
163160 describe ( 'GuestUser class' , ( ) => {
164161 it ( 'should update displayName when set through property' , async ( ) => {
165-
166162 const { getGuestUser } = await import ( '../lib' )
167163 const guestUser = getGuestUser ( )
168164 const newName = 'Property Test User'
0 commit comments