Skip to content

Commit b5a46a3

Browse files
committed
revert(merge): use incoming change
1 parent 0a1efe7 commit b5a46a3

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/components/login-form.test.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cleanup, screen, setup, waitFor } from '@/core/test-utils';
1+
import { cleanup, fireEvent, render, screen, waitFor } from '@/core/test-utils';
22

33
import type { LoginFormProps } from './login-form';
44
import { LoginForm } from './login-form';
@@ -10,55 +10,58 @@ const onSubmitMock: jest.Mock<LoginFormProps['onSubmit']> = jest.fn();
1010
describe('LoginForm Form ', () => {
1111
const LOGIN_BUTTON = 'login-button';
1212
it('renders correctly', async () => {
13-
setup(<LoginForm />);
13+
render(<LoginForm />);
1414
expect(await screen.findByText(/Sign in/i)).toBeOnTheScreen();
1515
});
1616

1717
it('should display required error when values are empty', async () => {
18-
const { user } = setup(<LoginForm />);
18+
render(<LoginForm />);
1919

2020
const button = screen.getByTestId(LOGIN_BUTTON);
21-
expect(screen.queryByText(/Email is required/i)).not.toBeOnTheScreen();
22-
await user.press(button);
23-
expect(await screen.findByText(/Email is required/i)).toBeOnTheScreen();
21+
expect(screen.queryByText(/Username is required/i)).not.toBeOnTheScreen();
22+
fireEvent.press(button);
23+
expect(await screen.findByText(/Username is required/i)).toBeOnTheScreen();
2424
expect(screen.getByText(/Password is required/i)).toBeOnTheScreen();
2525
});
2626

2727
it('should display matching error when email is invalid', async () => {
28-
const { user } = setup(<LoginForm />);
28+
render(<LoginForm />);
2929

3030
const button = screen.getByTestId(LOGIN_BUTTON);
3131
const emailInput = screen.getByTestId('email-input');
32+
const usernameInput = screen.getByTestId('username-input');
3233
const passwordInput = screen.getByTestId('password-input');
3334

34-
await user.type(emailInput, 'yyyyy');
35-
await user.type(passwordInput, 'test');
36-
await user.press(button);
35+
fireEvent.changeText(emailInput, 'yyyy');
36+
fireEvent.changeText(usernameInput, ' ');
37+
fireEvent.changeText(passwordInput, 'test');
38+
fireEvent.press(button);
3739

40+
expect(screen.queryByText(/Username is required/i)).not.toBeOnTheScreen();
3841
expect(await screen.findByText(/Invalid Email Format/i)).toBeOnTheScreen();
39-
expect(screen.queryByText(/Email is required/i)).not.toBeOnTheScreen();
4042
});
4143

4244
it('Should call LoginForm with correct values when values are valid', async () => {
43-
const { user } = setup(<LoginForm onSubmit={onSubmitMock} />);
45+
render(<LoginForm onSubmit={onSubmitMock} />);
4446

4547
const button = screen.getByTestId(LOGIN_BUTTON);
46-
const emailInput = screen.getByTestId('email-input');
48+
const emailInput = screen.getByTestId('username-input');
4749
const passwordInput = screen.getByTestId('password-input');
4850

49-
await user.type(emailInput, 'youssef@gmail.com');
50-
await user.type(passwordInput, 'password');
51-
await user.press(button);
51+
fireEvent.changeText(emailInput, 'youssef');
52+
fireEvent.changeText(passwordInput, 'password');
53+
fireEvent.press(button);
5254
await waitFor(() => {
5355
expect(onSubmitMock).toHaveBeenCalledTimes(1);
5456
});
55-
// expect.objectContaining({}) because we don't want to test the target event we are receiving from the onSubmit function
57+
// undefined because we don't use second argument of the SubmitHandler
5658
expect(onSubmitMock).toHaveBeenCalledWith(
5759
{
58-
60+
email: undefined,
61+
username: 'youssef',
5962
password: 'password',
6063
},
61-
expect.objectContaining({}),
64+
undefined,
6265
);
6366
});
6467
});

0 commit comments

Comments
 (0)