react-code-dataset / recharts /test /util /useAnimationId.spec.tsx
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame
1.46 kB
import { describe, it, expect } from 'vitest';
import { renderHook } from '@testing-library/react';
import { useAnimationId } from '../../src/util/useAnimationId';
describe('useAnimationId', () => {
it('should return a unique animation id', () => {
const input = { foo: 'bar' };
const prefix = 'test-';
const { result } = renderHook(() => useAnimationId(input, prefix));
const animationId = result.current;
expect(animationId).toBeDefined();
expect(animationId.startsWith(prefix)).toBe(true);
});
it('should change animation id when input changes', () => {
const input1 = { foo: 'bar' };
const input2 = { foo: 'baz' };
const prefix = 'test-';
const { result, rerender } = renderHook(({ input }) => useAnimationId(input, prefix), {
initialProps: { input: input1 },
});
const animationId1 = result.current;
rerender({ input: input2 });
const animationId2 = result.current;
expect(animationId1).not.toEqual(animationId2);
});
it('should not change animation id when input does not change', () => {
const input1 = { foo: 'bar' };
const prefix = 'test-';
const { result, rerender } = renderHook(({ input }) => useAnimationId(input, prefix), {
initialProps: { input: input1 },
});
const animationId1 = result.current;
rerender({ input: input1 });
const animationId2 = result.current;
expect(animationId1).toBe(animationId2);
});
});