Repository navigation
Docs: Add componentName to getAllStoryFiles in Jest portable stories guide - #35036
Conversation
… portable stories guide The Jest version of getAllStoryFiles() was missing the componentName property in its return object, unlike the Vitest version which correctly computes and returns it. This caused componentName to be undefined when used as a fallback for meta.title in the test suite description. Fixes storybookjs#26925 Co-authored-by: storybookjs-bot <storybook-bot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR updates the Storybook Jest snapshot test documentation snippets to compute ChangesJest Snapshot Test Snippet Updates
🎯 1 (Trivial) | ⏱️ ~3 minutes Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This comment was marked as abuse.
This comment was marked as abuse.
@AliMahmoudDev, Can you please list all of your GitHub account handles? |
Issue
Fixes #26925
Problem
In the Jest migration guide for portable stories, the
getAllStoryFiles()function returns{ filePath, storyFile }but the consumer code destructurescomponentName:Since
componentNamewas never defined in the returned object, it was alwaysundefined, causingtitleto fallback toundefinedwhenmeta.titlewasn't set.The Vitest version of the same guide correctly computes and returns
componentName:What Changed
File:
docs/_snippets/portable-stories-jest-snapshot-test.mdAdded
componentNamecomputation to both the JavaScript and TypeScript versions ofgetAllStoryFiles()in the Jest portable stories snapshot test snippet:return storyFiles.map((filePath) => { const storyFile = require(filePath); + const componentName = path.basename(filePath).replace(/\.(stories|story)\.[^/.]+$/, \$/\); - return { filePath, storyFile }; + return { filePath, storyFile, componentName }; });This aligns the Jest code sample with the Vitest version and fixes the runtime error where
componentNamewould beundefined.How to test
Manual testing
Copy the updated Jest code sample from the docs and verify that:
componentNameis correctly extracted from the filename (e.g.,Button.stories.tsx→Button)meta.titlein the test suite descriptionType of change
Summary by CodeRabbit