Skip to content
Discussion options

You must be logged in to vote

You can select a checkbox with the data attribute data-select-all in a Storybook Vitest test using standard DOM methods on the story's canvas element. For example:

import { within, waitFor } from 'storybook/test';

play: async ({ canvasElement }) => {
  // Wait for the checkbox to be rendered if needed
  await waitFor(() => {
    const checkbox = canvasElement.querySelector('[data-select-all]');
    if (!checkbox) throw new Error('Checkbox not found');
  });

  // Get the checkbox
  const checkbox = canvasElement.querySelector('[data-select-all]');
  // You can now interact with or assert on the checkbox
}

If you use Testing Library queries, you can also do:

const canvas = within(canvasE…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@meeshan-dev
Comment options

@dosubot
Comment options

@meeshan-dev
Comment options

@dosubot
Comment options

Answer selected by meeshan-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant