🎯 Refactor test file for improved readability and consistency in formatting and mock function definitions
This commit is contained in:
@@ -7,10 +7,12 @@ import { ref } from 'vue';
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock('../../../src/utilities/tournament-query.js', () => ({
|
||||
queryAllTournaments: vi.fn(() => Promise.resolve([
|
||||
queryAllTournaments: vi.fn(() =>
|
||||
Promise.resolve([
|
||||
{ id: 1, name: 'Tournament 1', state: 'pending' },
|
||||
{ id: 2, name: 'Tournament 2', state: 'underway' }
|
||||
]))
|
||||
])
|
||||
)
|
||||
}));
|
||||
|
||||
vi.mock('../../../src/composables/useAsyncState.js', () => ({
|
||||
@@ -23,7 +25,7 @@ vi.mock('../../../src/composables/useAsyncState.js', () => ({
|
||||
data,
|
||||
isLoading,
|
||||
error,
|
||||
execute: vi.fn(async (fn) => {
|
||||
execute: vi.fn(async fn => {
|
||||
isLoading.value = true;
|
||||
error.value = null;
|
||||
try {
|
||||
@@ -58,15 +60,19 @@ describe('useChallongeTests', () => {
|
||||
|
||||
mockClient = ref({
|
||||
tournaments: {
|
||||
list: vi.fn(() => Promise.resolve([
|
||||
list: vi.fn(() =>
|
||||
Promise.resolve([
|
||||
{ id: 1, name: 'Test Tournament 1' },
|
||||
{ id: 2, name: 'Test Tournament 2' }
|
||||
])),
|
||||
get: vi.fn((id) => Promise.resolve({
|
||||
])
|
||||
),
|
||||
get: vi.fn(id =>
|
||||
Promise.resolve({
|
||||
id,
|
||||
name: `Tournament ${id}`,
|
||||
participants: []
|
||||
}))
|
||||
})
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
@@ -75,13 +81,8 @@ describe('useChallongeTests', () => {
|
||||
});
|
||||
|
||||
it('creates composable with initial state', () => {
|
||||
const {
|
||||
tournaments,
|
||||
loading,
|
||||
error,
|
||||
searchQuery,
|
||||
currentPage
|
||||
} = useChallongeTests(mockClient, apiVersion, tournamentScope);
|
||||
const { tournaments, loading, error, searchQuery, currentPage } =
|
||||
useChallongeTests(mockClient, apiVersion, tournamentScope);
|
||||
|
||||
expect(tournaments.value).toBeNull();
|
||||
expect(loading.value).toBe(false);
|
||||
@@ -104,11 +105,8 @@ describe('useChallongeTests', () => {
|
||||
});
|
||||
|
||||
it('filters tournaments by search query', async () => {
|
||||
const { testListTournaments, searchQuery, filteredTournaments } = useChallongeTests(
|
||||
mockClient,
|
||||
apiVersion,
|
||||
tournamentScope
|
||||
);
|
||||
const { testListTournaments, searchQuery, filteredTournaments } =
|
||||
useChallongeTests(mockClient, apiVersion, tournamentScope);
|
||||
|
||||
await testListTournaments();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user