This commit is contained in:
dap
2024-09-15 09:16:26 +08:00
28 changed files with 127 additions and 78 deletions

View File

@@ -5,7 +5,6 @@ import { useLockStore } from './lock';
describe('useLockStore', () => {
beforeEach(() => {
// 每个测试前重置 Pinia
setActivePinia(createPinia());
});

View File

@@ -63,12 +63,11 @@ describe('useAccessStore', () => {
store.tabs = [
{ fullPath: '/home', meta: {}, name: 'Home', path: '/home' },
] as any;
router.replace = vi.fn(); // 使用 vitest 的 mock 函数
router.replace = vi.fn();
await store.closeAllTabs(router);
expect(store.tabs.length).toBe(1); // 假设没有固定的标签页
// expect(router.replace).toHaveBeenCalled();
expect(store.tabs.length).toBe(1);
});
it('closes a non-affix tab', () => {
@@ -161,7 +160,7 @@ describe('useAccessStore', () => {
await store._bulkCloseByPaths(['/home', '/contact']);
expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('About');
expect(store.tabs[0]?.name).toBe('About');
});
it('closes all tabs to the left of the specified tab', async () => {
@@ -189,7 +188,7 @@ describe('useAccessStore', () => {
await store.closeLeftTabs(targetTab);
expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('Contact');
expect(store.tabs[0]?.name).toBe('Contact');
});
it('closes all tabs except the specified tab', async () => {
@@ -217,7 +216,7 @@ describe('useAccessStore', () => {
await store.closeOtherTabs(targetTab);
expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('About');
expect(store.tabs[0]?.name).toBe('About');
});
it('closes all tabs to the right of the specified tab', async () => {
@@ -245,7 +244,7 @@ describe('useAccessStore', () => {
await store.closeRightTabs(targetTab);
expect(store.tabs).toHaveLength(1);
expect(store.tabs[0].name).toBe('Home');
expect(store.tabs[0]?.name).toBe('Home');
});
it('closes the tab with the specified key', async () => {

View File

@@ -24,7 +24,7 @@ describe('useUserStore', () => {
expect(store.userInfo).not.toBeNull();
expect(store.userRoles.length).toBeGreaterThan(0);
store.setUserInfo(null as any); // 重置用户信息
store.setUserInfo(null as any);
expect(store.userInfo).toBeNull();
expect(store.userRoles).toEqual([]);
});