🔧 Refactor test setup to use vi.spyOn for mocking useAuth module instead of direct mock replacement
This commit is contained in:
@@ -4,22 +4,20 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
import * as useAuthModule from '../../../src/composables/useAuth.js';
|
||||
import { useFeatureFlags } from '../../../src/composables/useFeatureFlags.js';
|
||||
import { useAuth } from '../../../src/composables/useAuth.js';
|
||||
|
||||
vi.mock('../../src/composables/useAuth.js');
|
||||
// Mock useAuth module
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
user: { isAdmin: false, permissions: [] },
|
||||
token: null,
|
||||
hasPermission: vi.fn(() => false)
|
||||
});
|
||||
|
||||
describe('useFeatureFlags', () => {
|
||||
beforeEach(() => {
|
||||
// Clear localStorage before each test
|
||||
localStorage.clear();
|
||||
|
||||
// Mock useAuth
|
||||
useAuth.mockReturnValue({
|
||||
user: { isAdmin: false, permissions: [] },
|
||||
token: null,
|
||||
hasPermission: vi.fn(perm => false)
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user