# test.web/core/loaders/stylesheet.fixture.ts

> 21 lines of code and 5 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-web-core-loaders-stylesheet-fixture-ts
Source text: https://banes-lab.com/source/testing/test.web/core/loaders/stylesheet.fixture.ts.txt

Listed in [test.web/core/loaders](https://banes-lab.com/api/source/testing/test.web/core/loaders.md), after [test.web/core/loaders/payload.loader.test.ts](https://banes-lab.com/source/testing/test.web/core/loaders/payload.loader.test.ts.md) and before [test.web/core/loaders/tree.loader.test.ts](https://banes-lab.com/source/testing/test.web/core/loaders/tree.loader.test.ts.md).

## Definitions

- `STYLESHEET_SELECTOR` (lexical_declaration, line 3)
- `LOAD_EVENT` (lexical_declaration, line 4)
- `LOADED_ATTRIBUTE` (lexical_declaration, line 5)
- `observer` (lexical_declaration, line 7)
- `reportLoaded` (lexical_declaration, line 9)

## Contained in

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

## Source

```typescript
import { afterAll, beforeAll } from "vitest";

const STYLESHEET_SELECTOR = "link[rel=stylesheet]";
const LOAD_EVENT = "load";
const LOADED_ATTRIBUTE = "data-loaded";

let observer: MutationObserver | null = null;

const reportLoaded = function reportLoaded(): void {
    for (const link of document.head.querySelectorAll(STYLESHEET_SELECTOR)) {
        if (!link.hasAttribute(LOADED_ATTRIBUTE)) {
            link.setAttribute(LOADED_ATTRIBUTE, "");
            link.dispatchEvent(new Event(LOAD_EVENT));
        }
    }
};

beforeAll(() => {
    observer = new MutationObserver(reportLoaded);
    observer.observe(document.head, { childList: true });
});

afterAll(() => {
    observer?.disconnect();
    observer = null;
});
```
