Middle
Have you ever written tests?
sobes.tech AI
Answer from AI
Yes, I have written tests for frontend applications using tools like Jest and React Testing Library. I usually write unit tests for components and functions, as well as integration tests to check interactions between components and APIs. For example, a React component test might look like this:
import { render, screen, fireEvent } from '@testing-library/react';
import Button from './Button';
test('button calls handler on click', () => {
const onClick = jest.fn();
render(<Button onClick={onClick}>Click me</Button>);
fireEvent.click(screen.getByText('Click me'));
expect(onClick).toHaveBeenCalledTimes(1);
});
This approach helps identify errors early and maintain code quality.