-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
options-compat.test.js
80 lines (60 loc) · 1.7 KB
/
options-compat.test.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { vnodeSpy, eventSpy } from '../../../test/_util/optionSpies';
import { render, createElement, Component, createRef } from '../../src';
import { setupRerender } from 'preact/test-utils';
import { setupScratch, teardown } from '../../../test/_util/helpers';
/** @jsx createElement */
describe('compat options', () => {
/** @type {HTMLDivElement} */
let scratch;
/** @type {() => void} */
let rerender;
/** @type {() => void} */
let increment;
/** @type {import('../../src/index').PropRef<HTMLButtonElement | null>} */
let buttonRef;
beforeEach(() => {
scratch = setupScratch();
rerender = setupRerender();
vnodeSpy.resetHistory();
eventSpy.resetHistory();
buttonRef = createRef();
});
afterEach(() => {
teardown(scratch);
});
class ClassApp extends Component {
constructor() {
super();
this.state = { count: 0 };
increment = () =>
this.setState(({ count }) => ({
count: count + 1
}));
}
render() {
return (
<button ref={buttonRef} onClick={increment}>
{this.state.count}
</button>
);
}
}
it('should call old options on mount', () => {
render(<ClassApp />, scratch);
expect(vnodeSpy).to.have.been.called;
});
it('should call old options on event and update', () => {
render(<ClassApp />, scratch);
expect(scratch.innerHTML).to.equal('<button>0</button>');
buttonRef.current.dispatchEvent(new Event('click'));
rerender();
expect(scratch.innerHTML).to.equal('<button>1</button>');
expect(vnodeSpy).to.have.been.called;
expect(eventSpy).to.have.been.called;
});
it('should call old options on unmount', () => {
render(<ClassApp />, scratch);
render(null, scratch);
expect(vnodeSpy).to.have.been.called;
});
});