Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
purinx committed Dec 11, 2023
1 parent be44560 commit e489d2e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/auth/sign-in/SignInForm/SignInForm.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Meta } from '@storybook/react';

import { SignInForm } from '.';

const meta: Meta = {
title: 'SignInForm',
component: SignInForm,
};

export default meta;

export const Component = () => (
<main className="container">
<SignInForm />
</main>
);

Component.args = {};
37 changes: 37 additions & 0 deletions src/app/auth/sign-in/SignInForm/SignInForm.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import '@testing-library/jest-dom';
import { render, screen, fireEvent } from '@testing-library/react';
import { act } from 'react-dom/test-utils';

import { SignInForm } from '.';

const dummy = {
email: '[email protected]',
password: 'password12345',
};

jest.mock('react-dom', () => ({
...jest.requireActual('react-dom'),
useFormState: () => [{ errors: {} }, jest.fn()],
}));

describe('SignInForm', () => {
test('入力できる', async () => {
render(<SignInForm />);

const form = await screen.findByRole('form');
expect(form).toHaveFormValues({
email: '',
password: '',
});

const emailInput = await screen.findByLabelText('Email');
const pwInput = await screen.findByLabelText('Password');

act(() => {
fireEvent.change(emailInput, { target: { value: dummy.email } });
fireEvent.change(pwInput, { target: { value: dummy.password } });
});

expect(form).toHaveFormValues(dummy);
});
});

0 comments on commit e489d2e

Please sign in to comment.