-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathmixedRender.js
85 lines (69 loc) · 3.03 KB
/
mixedRender.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
81
82
83
84
85
import { render } from '../src';
import {h, Component} from 'preact';
import chai, { expect } from 'chai';
import { spy, match } from 'sinon';
import sinonChai from 'sinon-chai';
chai.use(sinonChai);
describe('mixedRender()', () => {
it('should not render nested components when not white listed', () => {
let Test = spy(({ foo, children }) => <div bar={foo}><b>test child</b>{children}</div>);
Test.displayName = 'Test';
let rendered = render(
<section>
<Test foo={1}><span>asdf</span></Test>
</section>
, {}, { shallow: true, alwaysRenderedComponents: [] });
expect(rendered).to.equal(`<section><Test foo="1"><span>asdf</span></Test></section>`);
expect(Test).not.to.have.been.called;
});
it('should always render root component', () => {
let Test = spy(({ foo, children }) => <div bar={foo}><b>test child</b>{children}</div>);
Test.displayName = 'Test';
let rendered = render(
<Test foo={1}>
<span>asdf</span>
</Test>
, {}, { shallow: true, alwaysRenderedComponents: [] });
expect(rendered).to.equal(`<div bar="1"><b>test child</b><span>asdf</span></div>`);
expect(Test).to.have.been.calledOnce;
});
it('should render nested components when they are white listed', () => {
let Test = spy(({ foo, children }) => <div bar={foo}><b>test child</b>{children}</div>);
Test.displayName = 'Test';
let rendered = render(
<section>
<Test foo={1}><span>asdf</span></Test>
</section>
, undefined, { alwaysRenderedComponents: ['Test'] });
expect(rendered).to.equal(`<section><div bar="1"><b>test child</b><span>asdf</span></div></section>`);
expect(Test).to.have.been.called;
});
it('should not render nested components inside a whitelisted component', () => {
let Test = spy(({ foo, children }) => <div bar={foo}><b>test child</b>{children}</div>);
let Ignored = spy(({ title, children }) => <h2>This {title} should not be rendered</h2>);
Test.displayName = 'Test';
Ignored.displayName = 'Ignored';
let rendered = render(
<section>
<Test foo={1}><Ignored title={'FooBarTitle'}/></Test>
</section>
, {}, { shallow: true, alwaysRenderedComponents: ['Test'] });
expect(rendered).to.equal(`<section><div bar="1"><b>test child</b><Ignored title="FooBarTitle"></Ignored></div></section>`);
expect(Test).to.have.been.called;
expect(Ignored).to.not.have.been.called;
});
it('should render deeply nested components when all are white listed', () => {
let Test = spy(({ foo, children }) => <div bar={foo}><b>test child</b>{children}</div>);
let Ignored = spy(({ title, children }) => <h2>This {title} should be rendered</h2>);
Test.displayName = 'Test';
Ignored.displayName = 'Ignored';
let rendered = render(
<section>
<Test foo={1}><Ignored title={'FooBarTitle'}/></Test>
</section>
, {}, { shallow: true, alwaysRenderedComponents: ['Test', 'Ignored'] });
expect(rendered).to.equal(`<section><div bar="1"><b>test child</b><h2>This FooBarTitle should be rendered</h2></div></section>`);
expect(Test).to.have.been.called;
expect(Ignored).to.have.been.called;
});
});