front/__tests__/Card.test.tsx.no
2024-10-19 08:16:51 +03:00

24 lines
712 B
Plaintext

import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import Card from '../src/components/home/Card.jsx';
describe('Card Component', () => {
it('should render the Card component with the given ID', () => {
const testId = '123';
render(<Card id={testId} />);
const cardElement = screen.getByText(/123/i);
expect(cardElement).toBeInTheDocument();
});
it('should store the ID in local storage when clicked', () => {
const testId = '456';
render(<Card id={testId} />);
const cardElement = screen.getByText(/456/i);
fireEvent.click(cardElement);
expect(localStorage.setItem).toHaveBeenCalledWith('selectedId', testId);
});
});