/
githubmirror
/
preact
Обзор
Документация
Войти
/
githubmirror
/
preact
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
hooks/test/browser/useRef.test.jsx
48 строк
907 B
Ryan Christian
test: Switch tests to use `.jsx` file extension (#4925)
29 сен 2025, 16:58
Не верифицирован
29 сен 2025, 16:58
8e3e4ce
Код
Авторство
О чём код?
import { createElement, render } from 'preact'; import { setupScratch, teardown } from '../../../test/_util/helpers'; import { useRef } from 'preact/hooks'; describe('useRef', () => { /** @type {HTMLDivElement} */ let scratch; beforeEach(() => { scratch = setupScratch(); }); afterEach(() => { teardown(scratch); }); it('provides a stable reference', () => { const values = []; function Comp() { const ref = useRef(1); values.push(ref.current); ref.current = 2; return null; } render(<Comp />, scratch); render(<Comp />, scratch); expect(values).to.deep.equal([1, 2]); }); it('defaults to undefined', () => { const values = []; function Comp() { const ref = useRef(); values.push(ref.current); ref.current = 2; return null; } render(<Comp />, scratch); render(<Comp />, scratch); expect(values).to.deep.equal([undefined, 2]); }); });