-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Exception in enter key callback on editable or copyable Paragraph (
#33976) * fix: Exception on enter key callback * Move spyOn position
- Loading branch information
Showing
2 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
components/typography/__tests__/enter-key-callback.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import KeyCode from 'rc-util/lib/KeyCode'; | ||
import Paragraph from '../Paragraph'; | ||
|
||
test('Callback on enter key is triggered', () => { | ||
const onEditStart = jest.fn(); | ||
const onCopy = jest.fn(); | ||
|
||
const wrapper = mount( | ||
<Paragraph | ||
copyable={{ | ||
onCopy, | ||
}} | ||
editable={{ | ||
onStart: onEditStart, | ||
}} | ||
> | ||
test | ||
</Paragraph>, | ||
); | ||
const timer: any = 9527; | ||
jest.spyOn(window, 'setTimeout').mockReturnValue(timer); | ||
jest.spyOn(window, 'clearTimeout'); | ||
// must copy first, because editing button will hide copy button | ||
wrapper.find('.ant-typography-copy').at(0).simulate('keyup', { keyCode: KeyCode.ENTER }); | ||
wrapper.find('.anticon-edit').at(0).simulate('keyup', { keyCode: KeyCode.ENTER }); | ||
|
||
expect(onEditStart.mock.calls.length).toBe(1); | ||
expect(onCopy.mock.calls.length).toBe(1); | ||
jest.restoreAllMocks(); | ||
}); |