# test.govlab/patterns/core/validators/markup.validator.test.ts

> 26 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-patterns-core-validators-markup-validator-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/patterns/core/validators/markup.validator.test.ts.txt

Listed in [test.govlab/patterns/core/validators](https://banes-lab.com/api/source/testing/test.govlab/patterns/core/validators.md), after [test.govlab/patterns/core/validators/graph.validator.test.ts](https://banes-lab.com/source/testing/test.govlab/patterns/core/validators/graph.validator.test.ts.md) and before [test.govlab/patterns/core/validators/report.validator.test.ts](https://banes-lab.com/source/testing/test.govlab/patterns/core/validators/report.validator.test.ts.md).

## Contained in

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

## Source

```typescript
import {
    MALFORMED_ROOT,
    MISSING_VIEWBOX,
    forbiddenToken,
} from "@govlab/patterns/configuration/strings/markup.strings.ts";
import { assertHardened, hardenIssues } from "@govlab/patterns/core/validators/markup.validator.ts";
import { describe, expect, it } from "vitest";

const SAFE = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"></svg>';

describe("the markup hardening check", () => {
    it("passes a bounded, script-free SVG", () => {
        expect(hardenIssues(SAFE)).toStrictEqual([]);
        expect(() => {
            assertHardened(SAFE, "safe");
        }).not.toThrow();
    });

    it("names every forbidden token, a missing viewBox and a malformed root", () => {
        expect(hardenIssues("<g><script/></g>")).toStrictEqual([
            forbiddenToken("<script"),
            MISSING_VIEWBOX,
            MALFORMED_ROOT,
        ]);
        expect(() => {
            assertHardened("<g/>", "broken");
        }).toThrow("broken");
    });
});
```
