# FakeFeatureQuery

A scripted [`FeatureQuery`](https://docs.mapcairn.com/api/core/FeatureQuery.md) with no network and no timers.

This is a class exported by `@mapcairn/core`, checked against version 0.2.0.

## Signature

```ts
import { FakeFeatureQuery } from "@mapcairn/core";
 
class FakeFeatureQuery implements FeatureQuery
```

## Description

How to script it:
- `respondWith(hits)` says what lies inside whatever area is asked about.
 It answers every later query with the first `limit` of those hits in the
 layers asked about, each feature once, as the port rules require. With no
 script it finds nothing.
- `failWith(kind)` makes every query reject with a `FeatureQueryError` until
 `clearFailure()`.
- `hold()` keeps every later query pending until the function it returns is
 called, which also lets the queries held since then answer. Releasing an
 earlier hold does not free queries made under a later one.
- A request is checked first: a `limit` that is not a whole number of at
 least 1, or an `area` that is not a polygon with at least one closed ring
 on the globe, rejects as `invalid`. The check comes before any hold or failure, so a bad request
 never uses a script.
- Every query honours its `AbortSignal` by rejecting with a
 `FeatureQueryError` of kind `aborted`, before the call or while it is
 held.
- `calls` records what the ui asked.

## Properties

### calls

```ts
readonly calls: FeatureQueryRequest[];
```

Every request the ui made, in order, including ones that were refused or failed.

## Methods

### clearFailure

```ts
clearFailure(): void;
```

Stops [`FakeFeatureQuery`](https://docs.mapcairn.com/api/core/FakeFeatureQuery.md) failing queries.

### failWith

```ts
failWith(kind: FakeFeatureQueryFailure): void;
```

Makes every later query reject with a `FeatureQueryError` of this kind.

- `kind` (`FakeFeatureQueryFailure`)

### hold

```ts
hold(): () => void;
```

Holds every later query until the returned function is called. A later
`hold` replaces this one for queries made after it, and releasing this one
then leaves that hold in place.

### respondWith

```ts
respondWith(hits: readonly SelectionHit[]): void;
```

Answers every later query from these hits.

- `hits` (`readonly SelectionHit[]`)

### within

```ts
within(request: FeatureQueryRequest): Promise<readonly SelectionHit[]>;
```

Checks the request, then answers as scripted: the first `limit` of the scripted hits in the layers asked about, a held, failed or aborted query, or no hits when nothing is scripted.

- `request` (`FeatureQueryRequest`)

## See also

- [`FeatureQuery`](https://docs.mapcairn.com/api/core/FeatureQuery.md)
- [`FeatureQueryRequest`](https://docs.mapcairn.com/api/core/FeatureQueryRequest.md)
- [`FakeFeatureQueryFailure`](https://docs.mapcairn.com/api/core/FakeFeatureQueryFailure.md)
- [`SelectionHit`](https://docs.mapcairn.com/api/core/SelectionHit.md)

Source: [packages/core/src/fakes/FakeFeatureQuery.ts:90](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/fakes/FakeFeatureQuery.ts#L90)
