PliWould/components/__tests__/MeasurementInput-test.tsx

19 lines
793 B
TypeScript
Raw Normal View History

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