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

Args: Fix args inference for null values #13029

Merged
merged 3 commits into from
Nov 6, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this example have a type?

},
"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