Skip to content

Docs: Add afterEach guidance#32156

Merged
kylegach merged 3 commits into
nextfrom
docs-after-each
Aug 5, 2025
Merged

Docs: Add afterEach guidance#32156
kylegach merged 3 commits into
nextfrom
docs-after-each

Conversation

@kylegach
Copy link
Copy Markdown
Contributor

@kylegach kylegach commented Jul 30, 2025

What I did

Add guidance for the afterEach function

Checklist for Contributors

Testing

Manual testing

  1. Sync this branch with locally running docs

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

Greptile Summary

This PR adds comprehensive documentation for the afterEach function in Storybook's interaction testing capabilities. The changes include:

Main Documentation Updates:

  • Added a new section in docs/writing-tests/interaction-testing.mdx explaining the afterEach lifecycle hook
  • Documents that afterEach runs after story rendering and play function completion
  • Explains the function can be used at project, component, or story levels
  • Provides clear guidance on appropriate use cases (post-interaction assertions, accessibility checks, logging)
  • Includes an important warning against using it for state resets, which could interfere with test result visibility

Code Examples:

  • Created docs/_snippets/after-each-in-meta.md with comprehensive examples across all supported frameworks
  • Follows Storybook's established multi-framework documentation pattern
  • Includes examples for Angular, Svelte (both CSF and traditional), React, Vue, and Web Components
  • Provides both JavaScript and TypeScript variants consistently
  • All examples demonstrate basic logging functionality to show the API usage

The documentation integrates well with Storybook's existing testing infrastructure, as evidenced by the afterEach function already being used internally by the a11y addon for accessibility testing. This PR fills a documentation gap for a feature that exists and is actively used within Storybook's ecosystem, making it available for end users who need post-interaction testing capabilities.

Confidence score: 5/5

  • This is a documentation-only PR that is extremely safe to merge with no risk of breaking production code
  • The documentation follows established patterns and conventions used throughout the Storybook codebase
  • All code examples are consistent, well-formatted, and demonstrate the API correctly across multiple frameworks
  • No files requiring more attention

Context used:

Context - When documenting code snippets, ensure to include Svelte CSF and CSF examples, and also include JS and TypeScript variants. (link)

@kylegach kylegach self-assigned this Jul 30, 2025
@kylegach kylegach requested a review from jonniebigodes as a code owner July 30, 2025 22:14
@kylegach kylegach added patch:yes Bugfix & documentation PR that need to be picked to main branch ci:docs Run the CI jobs for documentation checks only. labels Jul 30, 2025
@kylegach kylegach requested a review from kasperpeulen July 30, 2025 22:14
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

Comment on lines +154 to +156
async afterEach(context) {
console.log(`✅ Tested ${context.name} story`);
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

style: Inconsistent emoji usage - only the web-components JS example includes ✅ emoji while others don't

Suggested change
async afterEach(context) {
console.log(`Tested ${context.name} story`);
},
async afterEach(context) {
console.log(`Tested ${context.name} story`);
},

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jul 30, 2025

View your CI Pipeline Execution ↗ for commit 8a3bc56

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 13s View ↗

☁️ Nx Cloud last updated this comment at 2025-08-05 16:46:01 UTC

@Stadly
Copy link
Copy Markdown

Stadly commented Jul 31, 2025

You mention running accessibility tests in afterEach. How can I do that? My impression is that I cannot control at which time a11y tests are run using the a11y addon.

@kylegach
Copy link
Copy Markdown
Contributor Author

@Stadly — I only included that as an example of what could be done. However, that's probably more confusing than helpful, as we already have a way to do a11y checks: addon-a11y.

I've changed the explanation to avoid that confusion.

Fwiw, addon-a11y itself uses beforeEach to run the checks.

@kylegach kylegach merged commit b6edefe into next Aug 5, 2025
8 checks passed
@kylegach kylegach deleted the docs-after-each branch August 5, 2025 17:30
yannbf pushed a commit that referenced this pull request Aug 11, 2025
Docs: Add `afterEach` guidance
(cherry picked from commit b6edefe)
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Aug 11, 2025
@ndelangen ndelangen removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:docs Run the CI jobs for documentation checks only. documentation patch:done Patch/release PRs already cherry-picked to main/release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants