This repository was archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathrenderReact-test.js
53 lines (38 loc) · 1.59 KB
/
renderReact-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
import jsdom from 'jsdom';
import { assert } from 'chai';
import sinon from 'sinon';
import ExampleReactComponent from './components/ExampleReactComponent';
import { renderReact } from '..';
import * as renderReactClientModule from '../lib/client';
import * as renderReactServerModule from '../lib/server';
describe('renderReact', () => {
it('exists', () => {
assert.isFunction(renderReact);
assert.equal(renderReact.length, 2);
});
it('calls renderReactServer', () => {
const renderReactServerSpy = sinon.spy(renderReactServerModule, 'renderReactServer');
renderReact('ExampleReactComponent', ExampleReactComponent)({ name: 'Desmond' });
assert(renderReactServerSpy.calledOnce, `renderReactServer was not called once but ${renderReactServerSpy.callCount} times`);
renderReactServerSpy.restore();
});
it('calls renderReactClient', (done) => {
const result = renderReact('ExampleReactComponent', ExampleReactComponent)({ name: 'Desmond' });
jsdom.env(result, (err, window) => {
if (err) {
done(err);
return;
}
const renderReactClientSpy = sinon.spy(renderReactClientModule, 'renderReactClient');
global.window = window;
global.document = window.document;
// Calling it again for the client.
renderReact('ExampleReactComponent', ExampleReactComponent);
assert(renderReactClientSpy.calledOnce, `renderReactClient was not called once but ${renderReactClientSpy.callCount} times`);
renderReactClientSpy.restore();
delete global.window;
delete global.document;
done();
});
});
});