csusmGDSC / website

The main website for GDSC-CSUSM
https://gdsc-club-sm.vercel.app
4 stars 0 forks source link

[COMPONENT TESTING] - Upcoming & Past Events #73

Open JaedonSpurlock01 opened 5 days ago

JaedonSpurlock01 commented 5 days ago

We need to write Jest test cases for the Upcoming and Past Events component. The goal of this issue is to ensure that the component functions as expected by testing its rendering, behavior, and edge cases.

Acceptance Criteria

Testing Instructions

Additional Resources Jest Documentation

To get you started, here is some example code with Jest, feel free to use these or the docs,

import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom'; // for extra matchers like `toBeInTheDocument`
import { <ComponentName> } from '../path/to/component';

describe('<ComponentName> Component Tests', () => {

  it('renders without crashing', () => {
    render(<ComponentName />);
    const element = screen.getByTestId('<component-testid>');
    expect(element).toBeInTheDocument();
  });

  it('renders with correct props', () => {
    const { getByText } = render(<ComponentName propName="Test Prop" />);
    expect(getByText('Test Prop')).toBeInTheDocument();
  });

  it('handles click event correctly', () => {
    const handleClick = jest.fn();
    render(<ComponentName onClick={handleClick} />);
    const button = screen.getByRole('button');
    fireEvent.click(button);
    expect(handleClick).toHaveBeenCalledTimes(1);
  });

  // Add more specific tests for the component as needed

  it('matches snapshot', () => {
    const { asFragment } = render(<ComponentName />);
    expect(asFragment()).toMatchSnapshot();
  });
});