Skip to content

Commit

Permalink
Merge pull request #13029 from storybookjs/fix/default-argtypes-infer…
Browse files Browse the repository at this point in the history
…ence

Args: Fix args inference for null values
  • Loading branch information
shilman authored Nov 6, 2020
2 parents 7b13646 + 1fe2efa commit b7472d7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions addons/docs/src/frameworks/react/jsxDecorator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ describe('renderJsx', () => {
};

expect(renderJsx(<Container>yo dude</Container>, {})).toMatchInlineSnapshot(`
<div>
<Container className="super-container">
yo dude
</div>
</Container>
`);
});
});
Expand Down
4 changes: 1 addition & 3 deletions lib/client-api/src/ensureArgTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { combineParameters } from './parameters';
export const ensureArgTypes: ArgTypesEnhancer = (context) => {
const { argTypes: userArgTypes = {}, args = {} } = context.parameters;
if (!args) return userArgTypes;
const argTypes = mapValues(args, (arg, name) =>
arg !== null && typeof arg !== 'undefined' ? { name } : undefined
);
const argTypes = mapValues(args, (_arg, name) => ({ name }));
return combineParameters(argTypes, userArgTypes);
};
24 changes: 24 additions & 0 deletions lib/client-api/src/story_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,30 @@ describe('preview.story_store', () => {
expect(store.getRawStory('a', '1').parameters.argTypes).toEqual({ e: 'f', c: 'd' });
});

it('automatically infers argTypes from args', () => {
const store = new StoryStore({ channel });
addStoryToStore(store, 'a', '1', () => 0, { args: { a: null, b: 'hello', c: 9 } });
expect(store.getRawStory('a', '1').parameters.argTypes).toMatchInlineSnapshot(`
Object {
"a": Object {
"name": "a",
},
"b": Object {
"name": "b",
"type": Object {
"name": "string",
},
},
"c": Object {
"name": "c",
"type": Object {
"name": "number",
},
},
}
`);
});

it('adds user and default enhancers', () => {
const store = new StoryStore({ channel });
expect(store._argTypesEnhancers.length).toBe(1);
Expand Down

0 comments on commit b7472d7

Please sign in to comment.