dde272c4b8
CD - Docker - GHCR Images / Build and Push Images (push) Waiting to run
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
25 lines
750 B
TypeScript
25 lines
750 B
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
|
|
import { timeOperation } from './query-timing.js';
|
|
|
|
describe('timeOperation', () => {
|
|
it('returns the result and emits success with a numeric duration', async () => {
|
|
const emit = vi.fn();
|
|
|
|
const result = await timeOperation(() => Promise.resolve('ok'), emit);
|
|
|
|
expect(result).toBe('ok');
|
|
expect(emit).toHaveBeenCalledWith('success', expect.any(Number));
|
|
});
|
|
|
|
it('re-throws and emits failure when the operation rejects', async () => {
|
|
const emit = vi.fn();
|
|
const boom = new Error('boom');
|
|
|
|
await expect(timeOperation(() => Promise.reject(boom), emit)).rejects.toBe(
|
|
boom
|
|
);
|
|
expect(emit).toHaveBeenCalledWith('failure', expect.any(Number));
|
|
});
|
|
});
|