Skip to content

Commit

Permalink
Don't set arg in validateOptions if it would be undefined.
Browse files Browse the repository at this point in the history
Fixes #15630
  • Loading branch information
tmeasday committed Jul 22, 2021
1 parent 99b63c0 commit 039eeda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/client-api/src/args.test.ts
Expand Up @@ -185,6 +185,11 @@ describe('combineArgs', () => {
});

describe('validateOptions', () => {
// https://github.com/storybookjs/storybook/issues/15630
it('does not set args to `undefined` if they are unset', () => {
expect(validateOptions({}, { a: {} })).toStrictEqual({});
});

it('omits arg and warns if value is not one of options', () => {
expect(validateOptions({ a: 1 }, { a: { options: [2, 3] } })).toStrictEqual({});
expect(once.warn).toHaveBeenCalledWith(
Expand Down
4 changes: 3 additions & 1 deletion lib/client-api/src/args.ts
Expand Up @@ -72,7 +72,9 @@ export const combineArgs = (value: any, update: any): Args => {
export const validateOptions = (args: Args, argTypes: ArgTypes): Args => {
return Object.entries(argTypes).reduce((acc, [key, { options }]) => {
if (!options) {
acc[key] = args[key];
if (key in args) {
acc[key] = args[key];
}
return acc;
}

Expand Down

0 comments on commit 039eeda

Please sign in to comment.