Middle
Have you tested anything on the frontend?
sobes.tech AI
Answer from AI
Yes, on the frontend, components and user interfaces are usually tested using tools like Jest and React Testing Library (for React), or Cypress for end-to-end testing. For example, with Jest, you can write a test that checks if clicking a button calls the correct function:
import { render, fireEvent } from '@testing-library/react';
import MyButton from './MyButton';
test('clicking the button calls the handler', () => {
const onClick = jest.fn();
const { getByText } = render(<MyButton onClick={onClick}>Click me</MyButton>);
fireEvent.click(getByText('Click me'));
expect(onClick).toHaveBeenCalledTimes(1);
});
This approach helps ensure that the UI works as intended and that changes do not break functionality.