Here is my simplified example:
import { IonApp, IonInput, IonLabel, IonPage } from '@ionic/react';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { useState } from 'react';
const Example: React.FC = () => {
const [test, setTest] = useState('');
return (
<IonPage>
<IonLabel>{test}</IonLabel>
<IonInput placeholder="Test Input" onIonInput={(e) => setTest(e.detail.value!)}></IonInput>
</IonPage>
);
};
test('label should display test value when its is typed into the input', async () => {
const user = userEvent.setup();
const expected = 'Test Value';
render(
<IonApp>
<Example />
</IonApp>
);
await user.type(screen.getByPlaceholderText('Test Input'), expected);
await waitFor(() => {
expect(screen.getByText(expected)).toBeInTheDocument();
});
});
I also have my tests set up as per: Ionic React Unit Testing Setup | Ionic Documentation
When running the test above onIonInput
does not seem to be triggered by user.type
.