24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
import { afterEach, expect, it, vi } from 'vitest';
|
|
import { enableViewTransitions } from '../../src/lib/ui/motion/viewTransition.js';
|
|
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
|
|
it('allows navigation to continue when a transition is skipped or superseded', async () => {
|
|
let finish: () => void = () => {};
|
|
const finished = new Promise<void>(resolve => { finish = resolve; });
|
|
const complete = Promise.reject(new Error('navigation aborted'));
|
|
vi.stubGlobal('document', { startViewTransition: (update: () => Promise<void>) => {
|
|
void update().then(finish);
|
|
return { ready: Promise.reject(new DOMException('Skipped transition', 'AbortError')), finished };
|
|
} });
|
|
await enableViewTransitions({ complete });
|
|
await finished;
|
|
});
|
|
|
|
it('continues without animation when the browser cannot start a transition', async () => {
|
|
vi.stubGlobal('document', { startViewTransition: () => { throw new Error('Unavailable'); } });
|
|
await enableViewTransitions({ complete: Promise.resolve() });
|
|
vi.stubGlobal('document', {});
|
|
expect(enableViewTransitions({ complete: Promise.resolve() })).toBeUndefined();
|
|
});
|