import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
// Mock the animated counter hook to return the end value immediately
vi.mock('@/hooks/useAnimatedCounter', () => ({
useAnimatedCounter: ({ end }: { end: number }) => end,
}));
import { AnimatedNumber } from './AnimatedNumber';
describe('AnimatedNumber', () => {
it('renders the value', () => {
render();
expect(screen.getByText('42')).toBeInTheDocument();
});
it('applies custom className', () => {
const { container } = render(
);
const span = container.querySelector('span');
expect(span?.className).toContain('text-lg');
expect(span?.className).toContain('tabular-nums');
});
it('uses format function when provided', () => {
render(
`$${n}`} />
);
expect(screen.getByText('$1500')).toBeInTheDocument();
});
it('formats large numbers with locale string', () => {
render();
// toLocaleString will format 1000 — the exact output depends on locale
const span = screen.getByText((content) => content.includes('1'));
expect(span).toBeInTheDocument();
});
});