Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
import { describe, expect, it, vi } from 'vitest';
import { trackAsyncTask } from './trackAsyncTask';
describe('trackAsyncTask', () => {
it('reports loading until the tracked task settles', async () => {
let resolveTask: (() => void) | undefined;
const task = new Promise<void>((resolve) => {
resolveTask = resolve;
});
const onLoadingChanged = vi.fn();
const tracked = trackAsyncTask(() => task, onLoadingChanged);
expect(onLoadingChanged).toHaveBeenCalledWith(true);
expect(onLoadingChanged).not.toHaveBeenCalledWith(false);
resolveTask?.();
await tracked;
expect(onLoadingChanged).toHaveBeenLastCalledWith(false);
});
it('clears loading when the task rejects', async () => {
const onLoadingChanged = vi.fn();
await expect(trackAsyncTask(() => Promise.reject(new Error('failed')), onLoadingChanged)).rejects.toThrow('failed');
expect(onLoadingChanged.mock.calls).toEqual([[true], [false]]);
});
});