Skip to content

First Story (Jest)

Create a test file (e.g. src/login.story.test.ts):

import { expect } from '@jest/globals';
import { story } from 'executable-stories-jest';
describe('Login', () => {
it('user logs in successfully', () => {
story.init();
story.given('the user is on the login page');
story.when('the user submits valid credentials');
story.then('the user should see the dashboard');
expect(true).toBe(true); // replace with real assertions
});
});

Use story.init() at the start of the test (no task; Jest gets the test name from expect.getState()), then story.given, story.when, story.then to mark steps.

Terminal window
pnpm jest

The reporter writes to your configured formats and paths. For Markdown output (for example docs/user-stories.md), the story above looks like:

### User logs in successfully
- **Given** the user is on the login page
- **When** the user submits valid credentials
- **Then** the user should see the dashboard

Jest story & doc API — steps, doc methods, and options.

Converting existing Jest tests — adopt executable-stories without rewriting existing tests.

Recipes (Jest) — more examples.