new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Storybook · all subjects

play functions & interactions

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

storybook/test package exports

The storybook/test package exports instrumented versions of: @vitest/spy (for mocking), @vitest/expect (based on chai for assertions), @testing-library/dom (for DOM queries), and @testing-library/user-event (for user interactions). These exported tools can be imported directly from 'storybook/test'.

Instrumentation enables interactions panel debugging

The instrumented versions of testing utilities exported from storybook/test allow developers to debug those methods in the interactions panel, providing visibility into test execution within Storybook.

storybook/test imports example

Import testing utilities from storybook/test like this: import { expect, fn, userEvent, within } from 'storybook/test';

Play function with testing utilities example

The following example shows a complete play function using storybook/test utilities to test a Button component: it uses within() to get a canvas context, userEvent.click() to simulate a click, and expect() to assert that a mock function was called. Code: export const Demo = { play: async ({ args, canvasElement }) => { const canvas = within(canvasElement); await userEvent.click(canvas.getByRole('button')); await expect(args.onClick).toHaveBeenCalled(); } };

fn() creates mock function for args

The fn() utility from storybook/test creates a mock function that can be passed as an arg to a component and then asserted against in play functions to verify it was called.

within() provides scoped query context

The within() utility from @testing-library/dom returns a queries object scoped to a specific element, such as canvasElement in a play function, allowing queries like getByRole() to be executed within that scope.

Give your agent this brain