Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
fix: ignore __esModules flag when composing stories
Browse files Browse the repository at this point in the history
Jest and babel add a flag to help with mocking which impacts composeStories, that should be ignored.
  • Loading branch information
yannbf committed May 20, 2021
1 parent 75bfd1a commit c79b589
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion example/src/stories/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('GlobalConfig', () => {
});

// common in addons that need to communicate between manager and preview
test('should pass with decorators that ne addons channel', () => {
test('should pass with decorators that need addons channel', () => {
const PrimaryWithChannels = composeStory(stories.Primary, stories.default, {
decorators: [
(StoryFn: any) => {
Expand All @@ -76,6 +76,18 @@ test('should pass with decorators that ne addons channel', () => {
expect(buttonElement).not.toBeNull();
});

it('should ignore __esModules property from jest mocking', () => {
const mockedModule = {
__esModule: true,
default: { title: 'Components/Button' },
Primary: () => {},
};

expect(() => {
composeStories(mockedModule)
}).not.toThrow();
});

describe('Unsupported formats', () => {
test('should throw error StoryFn.story notation', () => {
const UnsupportedStory = () => <div>hello world</div>;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ export function composeStory<GenericArgs>(
* @param [globalConfig] - e.g. (import * as globalConfig from '../.storybook/preview') this can be applied automatically if you use `setGlobalConfig` in your setup files.
*/
export function composeStories<
T extends { default: Meta }
T extends { default: Meta, __esModule?: boolean }
>(storiesImport: T, globalConfig?: GlobalConfig) {
const { default: meta, ...stories } = storiesImport;
const { default: meta, __esModule, ...stories } = storiesImport;

// Compose an object containing all processed stories passed as parameters
const composedStories = Object.entries(stories).reduce(
Expand Down

0 comments on commit c79b589

Please sign in to comment.