Skip to content

Commit

Permalink
Merge pull request #16790 from storybookjs/16743-argTypeTargets-no-args
Browse files Browse the repository at this point in the history
Core: Ensure that `context.args` is always set
  • Loading branch information
shilman committed Nov 26, 2021
2 parents c5fab7f + 35d0096 commit 38aadfc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
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: {} }));
});
});
});

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

0 comments on commit 38aadfc

Please sign in to comment.