salix-front/test/vitest/__tests__/composables/useStateQuery.spec.js

43 lines
1.2 KiB
JavaScript

import { describe, expect, it, beforeEach } from 'vitest';
import { useStateQuery } from 'src/composables/useStateQuery';
describe('useStateQuery', () => {
const { add, isLoading, remove, reset, queries } = useStateQuery();
beforeEach(() => {
reset();
expect(queries.value.size).toBeFalsy();
});
it('should add two queries', async () => {
expect(queries.value.size).toBeFalsy();
const hash = add();
expect(queries.value.size).toBeTruthy();
expect(queries.value.has(hash)).toBeTruthy();
add();
expect(queries.value.size).toBe(2);
});
it('should add and remove loading state', async () => {
expect(isLoading().value).toBeFalsy();
const hash = add();
expect(isLoading().value).toBeTruthy();
remove(hash);
expect(isLoading().value).toBeFalsy();
});
it('should add and remove hash', async () => {
add();
add();
add();
const beforeCount = queries.value.size;
const hash = add();
expect(queries.value.has(hash)).toBeTruthy();
remove(hash);
expect(queries.value.has(hash)).toBeFalsy();
expect(queries.value.size).toBe(beforeCount);
});
});