get checkbox with data attr vitest addon #33436
-
|
@dosu, storybook vitest how to get checkbox with data attr data-select-all |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
You can select a checkbox with the data attribute 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(canvasElement);
const checkbox = await canvas.getByRole('checkbox', { name: /select all/i });
// Or by test id if you use data-testid
// const checkbox = await canvas.getByTestId('select-all');Using To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
You can select a checkbox with the data attribute
data-select-allin a Storybook Vitest test using standard DOM methods on the story's canvas element. For example:If you use Testing Library queries, you can also do: