react-code-dataset / recharts /test /chart /RechartsWrapper.spec.tsx
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame
1.02 kB
import React from 'react';
import { describe, it, expect, vi } from 'vitest';
import { fireEvent, render } from '@testing-library/react';
import { BarChart } from '../../src';
describe('RechartsWrapper', () => {
it('should call onMouseEnter, and onMouseLeave handlers', async () => {
const onMouseEnterSpy = vi.fn();
const onMouseLeaveSpy = vi.fn();
const { container } = render(
<BarChart width={800} height={400} onMouseEnter={onMouseEnterSpy} onMouseLeave={onMouseLeaveSpy} />,
);
const wrapper = container.querySelector('.recharts-wrapper');
expect(wrapper).toBeInTheDocument();
expect(onMouseEnterSpy).not.toHaveBeenCalled();
expect(onMouseLeaveSpy).not.toHaveBeenCalled();
fireEvent.mouseEnter(wrapper);
expect(onMouseEnterSpy).toHaveBeenCalledTimes(1);
expect(onMouseLeaveSpy).not.toHaveBeenCalled();
fireEvent.mouseLeave(wrapper);
expect(onMouseEnterSpy).toHaveBeenCalledTimes(1);
expect(onMouseLeaveSpy).toHaveBeenCalledTimes(1);
});
});