fix(testing): make ModelStatsDisplay snapshot test deterministic (#5236)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
Allen Hutchison 2025-07-30 15:09:32 -07:00 committed by GitHub
parent 7bc8766542
commit 498edb57ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 1 deletions

View File

@ -5,7 +5,7 @@
*/
import { render } from 'ink-testing-library';
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest';
import { ModelStatsDisplay } from './ModelStatsDisplay.js';
import * as SessionContext from '../contexts/SessionContext.js';
import { SessionMetrics } from '../contexts/SessionContext.js';
@ -38,6 +38,19 @@ const renderWithMockedStats = (metrics: SessionMetrics) => {
};
describe('<ModelStatsDisplay />', () => {
beforeAll(() => {
vi.spyOn(Number.prototype, 'toLocaleString').mockImplementation(function (
this: number,
) {
// Use a stable 'en-US' format for test consistency.
return new Intl.NumberFormat('en-US').format(this);
});
});
afterAll(() => {
vi.restoreAllMocks();
});
it('should render "no API calls" message when there are no active models', () => {
const { lastFrame } = renderWithMockedStats({
models: {},