storybookjs / testing-vue

MIT License
10 stars 6 forks source link

Fix TypeScript Types and argTypes generation #3

Closed dwightjack closed 2 years ago

dwightjack commented 3 years ago

This PR fixes two issues I've encountered trying v0.0.1 with a TypeScript project (and specs written in TS)

Type checking issue

In the spec file I received the following type checking errors:

const { Primary, Secondary } = composeStories(stories);

// ...

mount(Primary());
// ^-- Argument of type 'StoryFnVueReturnType' is not assignable to parameter of type 'VueComponent'.
//  Type 'string' is not assignable to type 'VueComponent'.
//  Expected 2 arguments, but got 0.

I am not completely if this is related to a change in the latest Storybook types. Anyway, I reworked the library types to fix the error.

ArgTypes generation.

Looking at the source code I guess that argTypes are collected only from globalConfig, but in storybook story files they can also be defined in Meta and in each individual story.

I changed the argTypes generation by merging them from args, the story,Meta, and globalConfig.

I also noticed that when running the examples on cypress ct, the console logged the following warnings:

image

image

So it seems that the onClick handler is not defined in the args and as a prop in argTypes.

I've updated the library to generate an empty function prop when a prop name either matches the argTypesRegex setting or an argType with an action property. If the prop is already a function (ie: has been set to a spy in the spec), it won't be changed.

dwightjack commented 3 years ago

@elevatebart @yannbf any update on this PR? I know you have lots of projects to maintain, so, if you think it might be helpful, I am available to help to maintain this library 😃.

yannbf commented 3 years ago

@elevatebart @yannbf any update on this PR? I know you have lots of projects to maintain, so, if you think it might be helpful, I am available to help to maintain this library 😃.

Hey @dwightjack thanks a lot for your contribution! Indeed, there are quite a few other projects hehe and would be super awesome to have a new helping hand! I'll try to check and test your contribution as soon as I can and will let you know!

@elevatebart if you could give a quick check that would be lovely!

dwightjack commented 2 years ago

Hi, just checking in. Any update on this PR? Is there something blocking it that I missed?

yannbf commented 2 years ago

Hey @dwightjack thank you so much for your patience! Things have been quite busy but I'll try my best to get this down and have a release soon!

yannbf commented 2 years ago

Hey @dwightjack thanks once again for your patience! I tried making some small changes but I don't have the privileges. I'll merge and make a couple fixes in the following version!