# test.govlab/docs/core/formatters/diagram.machine.formatter.test.ts

> 27 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-docs-core-formatters-diagram-machine-formatter-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/docs/core/formatters/diagram.machine.formatter.test.ts.txt

Listed in [test.govlab/docs/core/formatters](https://banes-lab.com/api/source/testing/test.govlab/docs/core/formatters.md), after [test.govlab/docs/core/formatters/diagram.formatter.test.ts](https://banes-lab.com/source/testing/test.govlab/docs/core/formatters/diagram.formatter.test.ts.md) and before [test.govlab/docs/core/formatters/diagram.sequence.formatter.test.ts](https://banes-lab.com/source/testing/test.govlab/docs/core/formatters/diagram.sequence.formatter.test.ts.md).

## Contained in

- [test.govlab/docs/core/formatters](https://banes-lab.com/anatomy/testing/folder-testing-test-govlab-docs-core-formatters.md)

## Source

```typescript
import { describe, expect, it } from "vitest";
import type { StateModel } from "@govlab/docs/types/diagram.types.ts";
import { createMermaidParser } from "@govlab/docs/core/adapters/diagram.adapter.ts";
import { emitStateDiagram } from "@govlab/docs/core/formatters/diagram.machine.formatter.ts";

const parsed = async function parsed(source: string): Promise<string | null> {
    const parser = await createMermaidParser();
    return parser.available ? parser.parse(source) : parser.reason;
};

const MODEL: StateModel = {
    initial: "idle",
    nodes: [
        { id: "idle", label: "idle" },
        { id: "awaiting", label: "awaiting reply" },
        { id: "applied", label: "applied" },
    ],
    transitions: [
        { from: "idle", label: "start", to: "awaiting" },
        { from: "awaiting", to: "applied" },
    ],
};

describe("emitStateDiagram", () => {
    it("emits a state diagram that parses and is deterministic", async () => {
        const out = emitStateDiagram(MODEL);
        expect(await parsed(out)).toBeNull();
        expect(emitStateDiagram(MODEL)).toBe(out);
    });
});
```
