Skip to content

Commit a360bbd

Browse files
authored
test: add test for useCombinedRefs hook (#2)
1 parent 5321bc0 commit a360bbd

File tree

3 files changed

+184
-4
lines changed

3 files changed

+184
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
},
2525
"devDependencies": {
2626
"@iconify-json/lucide": "1.1.131",
27+
"@testing-library/react": "^14.0.0",
2728
"@types/lodash": "^4.14.199",
2829
"@types/node": "^20.8.2",
2930
"@types/react": "18.2.24",

pnpm-lock.yaml

Lines changed: 162 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @vitest-environment happy-dom
2+
3+
import { render } from '@testing-library/react'
4+
import { expect, test } from 'vitest'
5+
6+
import { useCombinedRefs } from './useCombinedRefs'
7+
8+
test('should copy ref value to all passed instances', () => {
9+
const refs = [{ current: null }, { current: null }]
10+
11+
const TestComponent = () => {
12+
const ref = useCombinedRefs<HTMLDivElement>(...refs)
13+
return <div ref={ref} />
14+
}
15+
16+
const { container } = render(<TestComponent />)
17+
18+
refs.forEach((ref) => {
19+
expect(ref.current).toEqual(container.firstChild)
20+
})
21+
})

0 commit comments

Comments
 (0)