/
githubmirror
/
preact
Обзор
Документация
Войти
/
githubmirror
/
preact
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
hooks/test/browser/useDebugValue.test.jsx
70 строк
1 KB
Ryan Christian
test: Switch tests to use `.jsx` file extension (#4925)
29 сен 2025, 16:58
Не верифицирован
29 сен 2025, 16:58
8e3e4ce
Код
Авторство
О чём код?
import { createElement, render, options } from 'preact'; import { setupScratch, teardown } from '../../../test/_util/helpers'; import { useDebugValue, useState } from 'preact/hooks'; import { vi } from 'vitest'; describe('useDebugValue', () => { /** @type {HTMLDivElement} */ let scratch; beforeEach(() => { scratch = setupScratch(); }); afterEach(() => { teardown(scratch); delete options.useDebugValue; }); it('should do nothing when no options hook is present', () => { function useFoo() { useDebugValue('foo'); return useState(0); } function App() { let [v] = useFoo(); return <div>{v}</div>; } expect(() => render(<App />, scratch)).to.not.throw(); }); it('should call options hook with value', () => { let spy = (options.useDebugValue = vi.fn()); function useFoo() { useDebugValue('foo'); return useState(0); } function App() { let [v] = useFoo(); return <div>{v}</div>; } render(<App />, scratch); expect(spy).toHaveBeenCalledOnce(); expect(spy).toHaveBeenCalledWith('foo'); }); it('should apply optional formatter', () => { let spy = (options.useDebugValue = vi.fn()); function useFoo() { useDebugValue('foo', x => x + 'bar'); return useState(0); } function App() { let [v] = useFoo(); return <div>{v}</div>; } render(<App />, scratch); expect(spy).toHaveBeenCalledOnce(); expect(spy).toHaveBeenCalledWith('foobar'); }); });