You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ie split initStoryshots into a stories getter and a test runner
Is your feature request related to a problem? Please describe
I am using storybook to visually test my components, but have also a need for integration testing my components using Vue-Test-Utils. As I already have stories with decorators to mock certain plugins, I would like to use these stories as starting point of my integration tests.
Describe the solution you'd like
Currently I have implemented this as follows:
test/utils.js
// test/utils.jsimportaddons,{mockChannel}from'@storybook/addons'importloadFrameworkfrom'@storybook/addon-storyshots/dist/frameworks/frameworkLoader'// Required for Storyshotsaddons.setChannel(mockChannel())constisDisabled=(parameter)=>parameter===false||(parameter&¶meter.disable===true)exportfunctiongetStoryshots(storyKindRegex){const{ storybook, framework }=loadFramework({})constdata=storybook.raw().reduce((acc,item)=>{/* if (storyNameRegex && !item.name.match(storyNameRegex)) { return acc; } */if(storyKindRegex&&!item.kind.match(storyKindRegex)){returnacc}const{ kind,storyFn: render, parameters }=itemconstexisting=acc.find((i)=>i.kind===kind)const{ fileName }=item.parametersif(!isDisabled(parameters.storyshots)){if(existing){existing.children.push({ ...item, render, fileName })}else{acc.push({
kind,children: [{ ...item, render, fileName }],})}}returnacc},[])// Lets keep the original reduce method intact as much as possible// and transform the data to the tables that we need for Jestreturndata.map(({ kind, children })=>[kind,children.map((story)=>[story.name,story,{ ...story, framework }]),framework,])}
next I can implement my tests as follows:
MyComponent.test.js
// MyComponent.test.jsconststoryshots=getStoryshots(/MyComponent/i)describe.each(storyshots)('%s',(kind,stories)=>{describe.each(stories)('%s',(name,story,context)=>{letwrapperbeforeAll(()=>{constel=story.render()wrapper=mount(el)})test('Take Snapshot',()=>{expect(wrapper.html()).toMatchSnapshot()})// ... any other describe/test calls I would like to have})})
Describe alternatives you've considered
I could implement everything with VTU but I'd like to re-use the decorators I already added for mocking plugins & state.
Are you able to assist to bring the feature to reality?
Sure, let me know what you need
Additional context
I will admit that this use-case might be a bit edgy (and Vue specific?) because its the wrong way around. But given the current storyshots implementation it should be a fairly simple to export a getStoryshots method for users who want to have full control about their story tests.
The text was updated successfully, but these errors were encountered:
Strictly speaking, I think you're asking for something different than what's being discussed there. But I think we should discuss/solve it all in one place. cc @lifeiscontent@yannbf@tmeasday
Is your feature request related to a problem? Please describe
I am using storybook to visually test my components, but have also a need for integration testing my components using Vue-Test-Utils. As I already have stories with decorators to mock certain plugins, I would like to use these stories as starting point of my integration tests.
Describe the solution you'd like
Currently I have implemented this as follows:
test/utils.js
next I can implement my tests as follows:
MyComponent.test.js
Describe alternatives you've considered
I could implement everything with VTU but I'd like to re-use the decorators I already added for mocking plugins & state.
Are you able to assist to bring the feature to reality?
Sure, let me know what you need
Additional context
I will admit that this use-case might be a bit edgy (and Vue specific?) because its the wrong way around. But given the current storyshots implementation it should be a fairly simple to export a getStoryshots method for users who want to have full control about their story tests.
The text was updated successfully, but these errors were encountered: