Skip to content
This repository was archived by the owner on Nov 9, 2024. It is now read-only.

Commit 84cf087

Browse files
committed
test(useSingleton): add source variable error test
1 parent 20fcd93 commit 84cf087

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/useSingleton.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
84128
describe('disabled prop', () => {
85129
function App({disabled}) {
86130
const [source, target] = useSingleton({disabled});

0 commit comments

Comments
 (0)