Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Ensure that context.args is always set #16790

Merged
merged 1 commit into from Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions lib/store/src/prepareStory.test.ts
Expand Up @@ -527,6 +527,49 @@ describe('prepareStory', () => {
expect.objectContaining({ argsByTarget: { [NO_TARGET_NAME]: { a: 1 }, foo: { b: 2 } } })
);
});

it('always sets args, even when all are targetted', () => {
const renderMock = jest.fn();
const firstStory = prepareStory(
{
id,
name,
args: { b: 2 },
argTypes: { b: { name: 'b', target: 'foo' } },
},
{ id, title },
{ render: renderMock }
);

firstStory.unboundStoryFn({
args: firstStory.initialArgs,
hooks: new HooksContext(),
...firstStory,
} as any);
expect(renderMock).toHaveBeenCalledWith(
{},
expect.objectContaining({ argsByTarget: { foo: { b: 2 } } })
);
});

it('always sets args, even when none are set for the story', () => {
const renderMock = jest.fn();
const firstStory = prepareStory(
{
id,
name,
},
{ id, title },
{ render: renderMock }
);

firstStory.unboundStoryFn({
args: firstStory.initialArgs,
hooks: new HooksContext(),
...firstStory,
} as any);
expect(renderMock).toHaveBeenCalledWith({}, expect.objectContaining({ argsByTarget: {} }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmeasday shouldn't this be asserting something about args? and same for above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Args is the first argument ({})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aha! 💡

});
});
});

Expand Down
2 changes: 1 addition & 1 deletion lib/store/src/prepareStory.ts
Expand Up @@ -187,7 +187,7 @@ export function prepareStory<TFramework extends AnyFramework>(
...context,
allArgs: context.args,
argsByTarget,
args: argsByTarget[NO_TARGET_NAME],
args: argsByTarget[NO_TARGET_NAME] || {},
};
}

Expand Down