PliWould/components/__tests__/MeasurementInput-test.tsx

19 lines
737 B
TypeScript
Raw Normal View History

2024-07-01 17:05:24 +02:00
import { render, fireEvent, screen } from '@testing-library/react-native';
2024-07-01 15:15:43 +02:00
import { MeasurementInput } from '../MeasurementInput';
describe('MeasurementInput', () => {
it('renders correctly', () => {
2024-07-01 17:05:24 +02:00
render(<MeasurementInput units="foot" defaultValue={10} />);
const input = screen.getByLabelText('Enter measurement');
2024-07-01 15:15:43 +02:00
expect(input).toBeTruthy();
});
it('calls onValueSet when value is changed', () => {
const mockOnValueSet = jest.fn();
2024-07-01 17:05:24 +02:00
render(<MeasurementInput units="foot" defaultValue={10} onValueSet={mockOnValueSet} />);
const input = screen.getByLabelText('Enter measurement');
2024-07-01 15:15:43 +02:00
fireEvent.changeText(input, '20');
expect(mockOnValueSet).toHaveBeenCalledWith({ l: 20, u: 'foot' });
});
});