Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/submit.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { fireEvent, render } from '@testing-library/react';
import React from 'react';
import Input from '../src';

it('enter', () => {
const onFocus = jest.fn();
const onBlur = jest.fn();
const { container, getByText } = render(

Check notice

Code scanning / CodeQL

Unused variable, import, function or class

Unused variable getByText.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { container, getByText } = render(
const { container } = render(
<form
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
console.log('111');
}}
>
<Input onFocus={onFocus} onBlur={onBlur} />
<button type="submit">Submit</button>
</form>,
);
const inputEl = container.querySelector('input')!;
fireEvent.focus(inputEl);
fireEvent.keyDown(inputEl, { key: 'Enter' });
fireEvent.keyDown(inputEl, { key: 'Enter' });

// fireEvent.submit(inputEl);
// fireEvent.submit(inputEl);

// fireEvent.click(getByText('Submit'));
});