# test.build/core/formatters/metric.formatter.test.ts

> 13 lines of code and 0 definitions.

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

Listed in [test.build/core/formatters](https://banes-lab.com/api/source/testing/test.build/core/formatters.md), after [test.build/core/formatters/markdown.formatter.test.ts](https://banes-lab.com/source/testing/test.build/core/formatters/markdown.formatter.test.ts.md) and before [test.build/core/formatters/ontology.formatter.test.ts](https://banes-lab.com/source/testing/test.build/core/formatters/ontology.formatter.test.ts.md).

## Contained in

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

## Source

```typescript
import { describe, expect, it } from "vitest";
import { renderMetrics } from "@banes-lab/build-scripts/core/formatters/metric.formatter.ts";

describe("renderMetrics", () => {
    it("writes a typed module whose one export parses back to the metrics", () => {
        const metrics = { principles: 3, rules: 1, steps: 2, terms: 4 };
        const source = renderMetrics(metrics);
        expect(source.startsWith('import type { SiteMetrics } from "#types/metric.types";')).toBe(true);
        const start = source.indexOf("JSON.parse(") + "JSON.parse(".length;
        const literal: unknown = JSON.parse(source.slice(start, source.lastIndexOf(");")));
        const parsed: unknown = JSON.parse(String(literal));
        expect(parsed).toStrictEqual(metrics);
    });
});
```
