From f68a28d171ba43c20b8242ea37e9f2b7859ef56d Mon Sep 17 00:00:00 2001 From: Yuta Okuma Date: Sat, 20 Apr 2024 11:25:52 +0900 Subject: [PATCH] :white_check_mark: test: add mouse movement test --- src/components/Cursor/Cursor.test.tsx | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/Cursor/Cursor.test.tsx b/src/components/Cursor/Cursor.test.tsx index 6d22ad7e..f937dc68 100644 --- a/src/components/Cursor/Cursor.test.tsx +++ b/src/components/Cursor/Cursor.test.tsx @@ -1,4 +1,4 @@ -import { screen, render } from '@testing-library/react'; +import { screen, render, fireEvent, waitFor } from '@testing-library/react'; import '@testing-library/jest-dom'; import Cursor from './Cursor'; @@ -20,4 +20,25 @@ describe('src/components/Cursor/Cursor.test.tsx', () => { const cursorElement = screen.getByTestId('cursor'); expect(cursorElement).toBeInTheDocument(); }); + + it('should render the Cursor component with mouse movement', async () => { + const cursorElement = screen.getByTestId('cursor'); + const initialPosition = { + x: cursorElement.style.left, + y: cursorElement.style.top, + }; + + fireEvent.mouseMove(document, { + clientX: 100, + clinetY: 200, + }); + + await waitFor(() => { + expect(cursorElement.style.left).not.toBe(initialPosition.x); + }); + + await waitFor(() => { + expect(cursorElement.style.top).not.toBe(initialPosition.y); + }); + }); });