31 lines
865 B
JavaScript
31 lines
865 B
JavaScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { ref, nextTick } from 'vue';
|
|
import { stateQueryGuard } from 'src/router/hooks';
|
|
import { __test as testStateQuery } from 'src/stores/useStateQueryStore';
|
|
|
|
vi.mock('src/stores/useStateQueryStore', () => {
|
|
const isLoading = ref(true);
|
|
return {
|
|
useStateQueryStore: () => ({
|
|
isLoading: () => isLoading,
|
|
}),
|
|
__test: {
|
|
isLoading,
|
|
},
|
|
};
|
|
});
|
|
|
|
describe('stateQueryGuard', () => {
|
|
it('espera a que isLoading sea false antes de llamar a next()', async () => {
|
|
const next = vi.fn();
|
|
|
|
const guardPromise = stateQueryGuard(next);
|
|
expect(next).not.toHaveBeenCalled();
|
|
|
|
testStateQuery.isLoading.value = false;
|
|
await nextTick();
|
|
await guardPromise;
|
|
expect(next).toHaveBeenCalled();
|
|
});
|
|
});
|