# test.govlab/quality/core/predicates/location.predicate.test.ts

> 14 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-quality-core-predicates-location-predicate-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/quality/core/predicates/location.predicate.test.ts.txt

Listed in [test.govlab/quality/core/predicates](https://banes-lab.com/api/source/testing/test.govlab/quality/core/predicates.md), after [test.govlab/quality/core/predicates/knob.predicate.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/predicates/knob.predicate.test.ts.md) and before [test.govlab/quality/core/predicates/stylelint.predicate.test.ts](https://banes-lab.com/source/testing/test.govlab/quality/core/predicates/stylelint.predicate.test.ts.md).

## Contained in

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

## Source

```typescript
import { expect, test } from "vitest";
import { isInsideRoot } from "@govlab/quality/core/predicates/location.predicate.ts";
import path from "node:path";

const ROOT = path.resolve("workspace-root");
const BESIDE = path.join(path.dirname(ROOT), "other", "a.ts");

test("isInsideRoot accepts the root and every path below it, relative or absolute", () => {
    expect(isInsideRoot(ROOT, ROOT)).toBe(true);
    expect(isInsideRoot(ROOT, "src/a.ts")).toBe(true);
    expect(isInsideRoot(ROOT, path.join(ROOT, "..x", "a.ts"))).toBe(true);
});

test("isInsideRoot refuses a path that climbs out of the root or sits beside it", () => {
    expect(isInsideRoot(ROOT, "../a.ts")).toBe(false);
    expect(isInsideRoot(ROOT, BESIDE)).toBe(false);
});
```
