/
githubmirror
/
preact
Обзор
Документация
Войти
/
githubmirror
/
preact
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
hooks/test/browser/useCallback.test.jsx
39 строк
946 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 { useCallback } from 'preact/hooks'; describe('useCallback', () => { /** @type {HTMLDivElement} */ let scratch; beforeEach(() => { scratch = setupScratch(); }); afterEach(() => { teardown(scratch); }); it('only recomputes the callback when inputs change', () => { const callbacks = []; function Comp({ a, b }) { const cb = useCallback(() => a + b, [a, b]); callbacks.push(cb); return null; } render(<Comp a={1} b={1} />, scratch); render(<Comp a={1} b={1} />, scratch); expect(callbacks[0]).to.equal(callbacks[1]); expect(callbacks[0]()).to.equal(2); render(<Comp a={1} b={2} />, scratch); render(<Comp a={1} b={2} />, scratch); expect(callbacks[1]).to.not.equal(callbacks[2]); expect(callbacks[2]).to.equal(callbacks[3]); expect(callbacks[2]()).to.equal(3); }); });