# test.build/core/validators/element.validator.test.ts

> 23 lines of code and 0 definitions.

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

Listed in [test.build/core/validators](https://banes-lab.com/api/source/testing/test.build/core/validators.md), after [test.build/core/validators/definition.validator.test.ts](https://banes-lab.com/source/testing/test.build/core/validators/definition.validator.test.ts.md) and before [test.build/core/validators/figure.validator.test.ts](https://banes-lab.com/source/testing/test.build/core/validators/figure.validator.test.ts.md).

## Contained in

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

## Source

```typescript
import { describe, expect, it } from "vitest";
import { GENERIC_LINK_TEXT } from "@banes-lab/web/configuration/constants/link.constants.ts";
import { checkLinkNames } from "@banes-lab/build-scripts/core/validators/element.validator.ts";

const FILE = "index.html";

describe("checkLinkNames", () => {
    it("accepts a link named by its text, its aria-label, an image's alt or its title", () => {
        const html = `<a href="/a">The methodology</a><a href="/b" aria-label="Methodology"><i></i></a><a href="/c"><img alt="PAG" src="/x.png"></a><a href="/d" title="Terms"><i></i></a>`;
        expect(checkLinkNames(FILE, html)).toStrictEqual([]);
    });

    it("reports a link with no discernible name", () => {
        const findings = checkLinkNames(FILE, `<a href="/methodology"><i class="bi-cpu"></i></a>`);
        expect(findings).toHaveLength(1);
        expect(findings[0]?.message).toContain("/methodology");
    });

    it("reports a link whose whole text is a generic phrase, whatever its case and spacing", () => {
        expect(checkLinkNames(FILE, `<a href="/m">  Start </a><a href="/n">Read   More</a>`)).toHaveLength(2);
        expect(GENERIC_LINK_TEXT.has("start")).toBe(true);
    });

    it("accepts a generic word once the link text carries its context", () => {
        const html = `<a href="/m">Start<span class="visually-hidden"> — Methodology</span></a>`;
        expect(checkLinkNames(FILE, html)).toStrictEqual([]);
    });
});
```
