-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from axisj/test/onBlur
onBlur prop test
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { cleanup, render, waitFor, fireEvent } from '@testing-library/react'; | ||
import { ReactMultiEmail } from '../react-multi-email'; | ||
import React from 'react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
afterEach(cleanup); | ||
|
||
describe('ReactMultiEmail onBlur Tests', () => { | ||
it('does not call onBlur if the input was never focused', async () => { | ||
const onBlurMockFunc = jest.fn(); | ||
|
||
render( | ||
<ReactMultiEmail | ||
onBlur={onBlurMockFunc} | ||
getLabel={(email, index, removeEmail) => { | ||
return ( | ||
<div data-tag key={index}> | ||
<div data-tag-item>{email}</div> | ||
<span data-tag-handle onClick={() => removeEmail(index)}> | ||
× | ||
</span> | ||
</div> | ||
); | ||
}} | ||
/>, | ||
); | ||
|
||
expect(onBlurMockFunc).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('call the onBlur when the input area is blurred', async () => { | ||
const onBlurMockFunc = jest.fn(); | ||
|
||
const { getByRole } = render( | ||
<ReactMultiEmail | ||
onBlur={onBlurMockFunc} | ||
getLabel={(email, index, removeEmail) => { | ||
return ( | ||
<div data-tag key={index}> | ||
<div data-tag-item>{email}</div> | ||
<span data-tag-handle onClick={() => removeEmail(index)}> | ||
× | ||
</span> | ||
</div> | ||
); | ||
}} | ||
/>, | ||
); | ||
|
||
const input: HTMLElement | null = getByRole('textbox'); | ||
|
||
await waitFor(() => { | ||
fireEvent.focus(input); | ||
fireEvent.blur(input); | ||
}); | ||
|
||
expect(onBlurMockFunc).toHaveBeenCalledTimes(1); | ||
expect(input).not.toHaveFocus(); | ||
}); | ||
}); |
1afb398
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
react-multi-email – ./
react-multi-email-git-master-axframe.vercel.app
react-multi-email-axframe.vercel.app
react-multi-email.vercel.app