Skip to content

Commit

Permalink
Merge pull request #158 from axisj/test/onBlur
Browse files Browse the repository at this point in the history
onBlur prop test
  • Loading branch information
nhchoe authored Sep 19, 2023
2 parents 4af80de + 8311f13 commit 1afb398
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/onBlur.test.tsx
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();
});
});

1 comment on commit 1afb398

@vercel
Copy link

@vercel vercel bot commented on 1afb398 Sep 19, 2023

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

Please sign in to comment.