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

> 39 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-build-core-formatters-icons-formatter-test-ts
Source text: https://banes-lab.com/source/testing/test.build/core/formatters/icons.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/graph.formatter.test.ts](https://banes-lab.com/source/testing/test.build/core/formatters/graph.formatter.test.ts.md) and before [test.build/core/formatters/index.formatter.test.ts](https://banes-lab.com/source/testing/test.build/core/formatters/index.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 { FONT_ROUTE, SUBSET_FILE } from "@banes-lab/build-scripts/configuration/constants/icons.constants.ts";
import { describe, expect, it } from "vitest";
import {
    glyphTextOf,
    renderIconPaths,
    renderStylesheet,
} from "@banes-lab/build-scripts/core/formatters/icons.formatter.ts";

const ICON_PREFIX = "bi-";
const SWAP = "font-display: swap;";
const UNKNOWN = "no-such-glyph-anywhere";

describe("renderStylesheet", () => {
    it("declares the swapped face once and one glyph rule per name, nothing else", () => {
        const css = renderStylesheet(["x", "check2"]);
        expect(css.split(SWAP)).toHaveLength(2);
        expect(css).toContain(`${FONT_ROUTE}${SUBSET_FILE}`);
        expect(css).toContain(`.${ICON_PREFIX}x::before`);
        expect(css).toContain(`.${ICON_PREFIX}check2::before`);
        expect(css.split("::before {")).toHaveLength(4);
    });

    it("refuses a name the icon font has no glyph for", () => {
        expect(() => renderStylesheet([UNKNOWN])).toThrow(UNKNOWN);
    });
});

describe("glyphTextOf", () => {
    it("spells one character per declared icon and refuses an unknown one", () => {
        const glyphs = new Intl.Segmenter().segment(glyphTextOf(["x", "check2"]));
        expect([...glyphs]).toHaveLength(2);
        expect(() => glyphTextOf([UNKNOWN])).toThrow(UNKNOWN);
    });
});

describe("renderIconPaths", () => {
    it("maps each prefixed icon name to its path data and fill rule, typed by the web member", () => {
        const paths = [{ d: "M0 0h16v16H0z", evenOdd: true }];
        const module = renderIconPaths([["x", paths]]);
        expect(module).toContain(`["${ICON_PREFIX}x", ${JSON.stringify(paths)}]`);
        expect(module).toContain("export const ICON_PATHS: ReadonlyMap<string, readonly IconPath[]>");
        expect(module.startsWith("import type { IconPath }")).toBe(true);
    });
});
```
