blob: 28b06b0c3b8723829ad1d717227c1f937994e7ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import { createElement, render, options } from 'preact';
import { setupScratch, teardown } from '../../../test/_util/helpers';
import { useState } from 'preact/hooks';
import { addHookName } from 'preact/devtools';
/** @jsx createElement */
describe('addHookName', () => {
/** @type {HTMLDivElement} */
let scratch;
beforeEach(() => {
scratch = setupScratch();
});
afterEach(() => {
teardown(scratch);
delete options._addHookName;
});
it('should do nothing when no options hook is present', () => {
function useFoo() {
return addHookName(useState(0), 'foo');
}
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._addHookName = sinon.spy());
function useFoo() {
return addHookName(useState(0), 'foo');
}
function App() {
let [v] = useFoo();
return <div>{v}</div>;
}
render(<App />, scratch);
expect(spy).to.be.calledOnce;
expect(spy).to.be.calledWith('foo');
});
});
|