Skip to content

Commit

Permalink
Ensure that context.args is always set.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Nov 26, 2021
1 parent ca6a34d commit 35d0096
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 35d0096

Please sign in to comment.