Skip to content

Commit

Permalink
Allow promise to be returned from 'add()'
Browse files Browse the repository at this point in the history
  • Loading branch information
dchambers committed Aug 17, 2017
1 parent 2392767 commit a0647e4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion addons/storyshots/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function testStorySnapshots(options = {}) {

it(story.name, () => {
const context = { kind: group.kind, story: story.name };
options.test({ story, context });
return options.test({ story, context });
});
}
});
Expand Down
10 changes: 5 additions & 5 deletions addons/storyshots/src/test-bodies.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import renderer from 'react-test-renderer';
import shallow from 'react-test-renderer/shallow';

export const snapshotWithOptions = options => ({ story, context }) => {
const storyElement = story.render(context);
const tree = renderer.create(storyElement, options).toJSON();
expect(tree).toMatchSnapshot();
};
export const snapshotWithOptions = options => ({ story, context }) =>
Promise.resolve(story).then(storyVal => storyVal.render(context)).then(storyElement => {
const tree = renderer.create(storyElement, options).toJSON();
expect(tree).toMatchSnapshot();
});

export const snapshot = snapshotWithOptions({});

Expand Down
52 changes: 26 additions & 26 deletions app/react/src/client/preview/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,32 @@ export function renderMain(data, storyStore) {
story: selectedStory,
};

const element = story(context);

if (!element) {
const error = {
title: `Expecting a React element from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Did you forget to return the React element from the story?
Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
`,
};
return renderError(error);
}

if (!isReactRenderable(element)) {
const error = {
title: `Expecting a valid React element from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Seems like you are not returning a correct React element from the story.
Could you double check that?
`,
};
return renderError(error);
}

ReactDOM.render(element, rootEl);
return null;
return Promise.resolve(story(context)).then(element => {
if (!element) {
const error = {
title: `Expecting a React element from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Did you forget to return the React element from the story?
Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
`,
};
return renderError(error);
}

if (!isReactRenderable(element)) {
const error = {
title: `Expecting a valid React element from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Seems like you are not returning a correct React element from the story.
Could you double check that?
`,
};
return renderError(error);
}

ReactDOM.render(element, rootEl);
return null;
});
}

export default function renderPreview({ reduxStore, storyStore }) {
Expand Down

0 comments on commit a0647e4

Please sign in to comment.