This repository was archived by the owner on Nov 9, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,50 @@ it('updates `className` correctly', () => {
8181 ) . toBe ( true ) ;
8282} ) ;
8383
84+ it ( 'errors if source variable has not been passed to a <Tippy />' , ( ) => {
85+ const spy = jest . spyOn ( console , 'error' ) ;
86+
87+ function App1 ( ) {
88+ // eslint-disable-next-line
89+ const [ source , target ] = useSingleton ( ) ;
90+
91+ return (
92+ < >
93+ < Tippy />
94+ < Tippy singleton = { target } />
95+ < Tippy singleton = { target } />
96+ </ >
97+ ) ;
98+ }
99+
100+ function App2 ( ) {
101+ const [ source , target ] = useSingleton ( ) ;
102+
103+ return (
104+ < >
105+ < Tippy singleton = { source } />
106+ < Tippy singleton = { target } />
107+ < Tippy singleton = { target } />
108+ </ >
109+ ) ;
110+ }
111+
112+ render ( < App1 /> ) ;
113+
114+ expect ( spy ) . toHaveBeenCalledWith (
115+ [
116+ '@tippyjs/react: The `source` variable from `useSingleton()` has' ,
117+ 'not been passed to a <Tippy /> component.' ,
118+ ] . join ( ' ' ) ,
119+ ) ;
120+
121+ spy . mockReset ( ) ;
122+
123+ render ( < App2 /> ) ;
124+
125+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
126+ } ) ;
127+
84128describe ( 'disabled prop' , ( ) => {
85129 function App ( { disabled} ) {
86130 const [ source , target ] = useSingleton ( { disabled} ) ;
You can’t perform that action at this time.
0 commit comments