Skip to content

Commit c5f0875

Browse files
author
Guillermo Machado
committed
fix: fix test
1 parent 5fc7584 commit c5f0875

File tree

2 files changed

+7
-34
lines changed

2 files changed

+7
-34
lines changed

src/components/login-form.test.tsx

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

3-
import type { LoginFormProps } from './login-form';
43
import { LoginForm } from './login-form';
54

65
afterEach(cleanup);
76

8-
const onSubmitMock: jest.Mock<LoginFormProps['onSubmit']> = jest.fn();
9-
107
describe('LoginForm Form ', () => {
118
const LOGIN_BUTTON = 'login-button';
129
it('renders correctly', async () => {
@@ -18,9 +15,9 @@ describe('LoginForm Form ', () => {
1815
render(<LoginForm />);
1916

2017
const button = screen.getByTestId(LOGIN_BUTTON);
21-
expect(screen.queryByText(/Username is required/i)).not.toBeOnTheScreen();
18+
expect(screen.queryByText(/Email is required/i)).not.toBeOnTheScreen();
2219
fireEvent.press(button);
23-
expect(await screen.findByText(/Username is required/i)).toBeOnTheScreen();
20+
expect(await screen.findByText(/Email is required/i)).toBeOnTheScreen();
2421
expect(screen.getByText(/Password is required/i)).toBeOnTheScreen();
2522
});
2623

@@ -29,39 +26,13 @@ describe('LoginForm Form ', () => {
2926

3027
const button = screen.getByTestId(LOGIN_BUTTON);
3128
const emailInput = screen.getByTestId('email-input');
32-
const usernameInput = screen.getByTestId('username-input');
3329
const passwordInput = screen.getByTestId('password-input');
3430

3531
fireEvent.changeText(emailInput, 'yyyy');
36-
fireEvent.changeText(usernameInput, ' ');
3732
fireEvent.changeText(passwordInput, 'test');
3833
fireEvent.press(button);
3934

40-
expect(screen.queryByText(/Username is required/i)).not.toBeOnTheScreen();
35+
expect(screen.queryByText(/Email is required/i)).not.toBeOnTheScreen();
4136
expect(await screen.findByText(/Invalid Email Format/i)).toBeOnTheScreen();
4237
});
43-
44-
it('Should call LoginForm with correct values when values are valid', async () => {
45-
render(<LoginForm onSubmit={onSubmitMock} />);
46-
47-
const button = screen.getByTestId(LOGIN_BUTTON);
48-
const emailInput = screen.getByTestId('username-input');
49-
const passwordInput = screen.getByTestId('password-input');
50-
51-
fireEvent.changeText(emailInput, 'youssef');
52-
fireEvent.changeText(passwordInput, 'password');
53-
fireEvent.press(button);
54-
await waitFor(() => {
55-
expect(onSubmitMock).toHaveBeenCalledTimes(1);
56-
});
57-
// undefined because we don't use second argument of the SubmitHandler
58-
expect(onSubmitMock).toHaveBeenCalledWith(
59-
{
60-
email: undefined,
61-
username: 'youssef',
62-
password: 'password',
63-
},
64-
undefined,
65-
);
66-
});
6738
});

src/components/login-form.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { Button, ControlledInput, Text, View } from '@/ui';
88

99
const MIN_CHARS = 6;
1010
const schema = z.object({
11-
email: z.string().email('Invalid email format'),
11+
email: z
12+
.string({ required_error: 'Email is required' })
13+
.email('Invalid email format'),
1214
password: z
1315
.string({
1416
required_error: 'Password is required',

0 commit comments

Comments
 (0)