-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
renderTree.js
33 lines (25 loc) · 871 Bytes
/
renderTree.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
import { document } from 'global';
const riotForStorybook = require.requireActual('@storybook/riot');
function bootstrapADocumentAndReturnANode() {
const rootElement = document.createElement('div');
rootElement.id = 'root';
document.body = document.createElement('body');
document.body.appendChild(rootElement);
return rootElement;
}
function makeSureThatResultIsRenderedSomehow({ context, result, rootElement }) {
if (!rootElement.firstChild) {
riotForStorybook.render({
storyFn: () => result,
selectedKind: context.kind,
selectedStory: context.name,
});
}
}
function getRenderedTree(story, context) {
const rootElement = bootstrapADocumentAndReturnANode();
const result = story.render();
makeSureThatResultIsRenderedSomehow({ context, result, rootElement });
return rootElement;
}
export default getRenderedTree;