@@ -3,13 +3,22 @@ import { render, fireEvent } from '@testing-library/react';
3
3
import ClickAwayListener from '../src' ;
4
4
5
5
describe ( 'ClickAway Listener' , ( ) => {
6
- it ( 'should render properly' , ( ) => {
7
- const { getByText } = render (
6
+ it ( 'should render properly as "div" if no element is specified ' , ( ) => {
7
+ const { container } = render (
8
8
< ClickAwayListener onClickAway = { ( ) => null } >
9
- Hello World
9
+ Hello Default Div
10
10
</ ClickAwayListener >
11
11
) ;
12
- expect ( getByText ( / H e l l o W o r l d / i) ) . toBeTruthy ( ) ;
12
+ expect ( container . firstElementChild . tagName ) . toBe ( 'DIV' ) ;
13
+ } ) ;
14
+
15
+ it ( 'should be able to get rendered as a specified element' , ( ) => {
16
+ const { container } = render (
17
+ < ClickAwayListener as = "article" onClickAway = { ( ) => null } >
18
+ Hello Article
19
+ </ ClickAwayListener >
20
+ ) ;
21
+ expect ( container . firstElementChild . tagName ) . toBe ( 'ARTICLE' ) ;
13
22
} ) ;
14
23
15
24
it ( 'should take in props to be used like every other elements' , ( ) => {
@@ -21,20 +30,6 @@ describe('ClickAway Listener', () => {
21
30
expect ( getByText ( / H e l l o W o r l d / i) ) . toBeTruthy ( ) ;
22
31
expect ( getByText ( / H e l l o W o r l d / i) ) . toHaveProperty ( 'style' ) ;
23
32
} ) ;
24
- it ( 'it should wrap children around the element type specified' , ( ) => {
25
- const { container } = render (
26
- < ClickAwayListener as = "article" onClickAway = { ( ) => null } >
27
- hello best
28
- </ ClickAwayListener >
29
- ) ;
30
- expect ( container . firstElementChild . tagName ) . toBe ( 'ARTICLE' ) ;
31
- } ) ;
32
- it ( 'it should wrap children around div if no element type is specified' , ( ) => {
33
- const { container } = render (
34
- < ClickAwayListener onClickAway = { ( ) => null } > hello best</ ClickAwayListener >
35
- ) ;
36
- expect ( container . firstElementChild . tagName ) . toBe ( 'DIV' ) ;
37
- } ) ;
38
33
39
34
it ( 'should trigger onClickAway only when an element is clicked outside' , ( ) => {
40
35
const fakeHandleClick = jest . fn ( ) ;
0 commit comments