-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
compat.test.js
58 lines (45 loc) · 1.67 KB
/
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
import { createElement, render } from 'preact';
import { setupScratch, teardown } from '../../../test/_util/helpers';
import React from 'preact/compat'; // eslint-disable-line
describe('imported compat in preact', () => {
let scratch;
beforeEach(() => {
scratch = setupScratch();
});
afterEach(() => {
teardown(scratch);
});
it('should patch events', () => {
let spy = sinon.spy();
render(<div onClick={spy} />, scratch);
scratch.firstChild.click();
expect(spy).to.be.calledOnce;
const event = spy.args[0][0];
expect(event).to.haveOwnProperty('persist');
expect(event).to.haveOwnProperty('nativeEvent');
expect(typeof event.persist).to.equal('function');
expect(() => event.persist()).to.not.throw();
});
it('should normalize ondoubleclick event', () => {
let vnode = <div onDoubleClick={() => null} />;
expect(vnode.props).to.haveOwnProperty('ondblclick');
});
it('should normalize onChange for textarea', () => {
let vnode = <textarea onChange={() => null} />;
expect(vnode.props).to.haveOwnProperty('oninput');
expect(vnode.props).to.not.haveOwnProperty('onchange');
vnode = <textarea oninput={() => null} onChange={() => null} />;
expect(vnode.props).to.haveOwnProperty('oninput');
expect(vnode.props).to.not.haveOwnProperty('onchange');
});
it('should normalize class+className even on components', () => {
function Foo(props) {
return <div class={props.class} className={props.className}>foo</div>;
}
render(<Foo class="foo" />, scratch);
expect(scratch.firstChild.className).to.equal('foo');
render(null, scratch);
render(<Foo className="foo" />, scratch);
expect(scratch.firstChild.className).to.equal('foo');
});
});