# FakeLocationProvider

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

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

## Signature

```ts
import { FakeLocationProvider } from "@mapcairn/core";
 
class FakeLocationProvider implements LocationProvider
```

## Description

How to script it:
- `setFix(fix)` changes what `locate` resolves with.
- `failWith(kind)` makes `locate` reject with a `LocationError` until
 `clearFailure()`.
- `holdNext()` keeps the next `locate` pending until the handle settles it.
- With `supportsWatch`, `watch` registers handlers, and `emitFix` and
 `emitError` push to every active watcher. A watcher stops when its signal
 aborts. Without `supportsWatch`, `watch` is `undefined`.
- Every `locate` honours its signal by rejecting with `PortAbortError`.
- `locateCalls` records the options and `watcherCount` the live watchers.

## Constructors

### (constructor)

```ts
constructor(options?: FakeLocationProviderOptions);
```

Constructs a new instance of the `FakeLocationProvider` class

- `options?` (`FakeLocationProviderOptions`)

## Properties

### locateCalls

```ts
readonly locateCalls: (LocateOptions | undefined)[];
```

The options of every `locate` call, in order.

### supportsWatch

```ts
readonly supportsWatch: boolean;
```

Whether `watch` exists, as the constructor option set it.

### watch

```ts
readonly watch?: LocationProvider["watch"];
```

Registers handlers that `emitFix` and `emitError` push to, until the signal aborts. It is `undefined` when `supportsWatch` is false.

### watcherCount

```ts
readonly get watcherCount(): number;
```

The number of watchers that have not been aborted.

## Methods

### clearFailure

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

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

### emitError

```ts
emitError(error: Error): void;
```

Delivers an error to every active watcher.

- `error` (`Error`)

### emitFix

```ts
emitFix(fix: LocationFix): void;
```

Delivers a fix to every active watcher.

- `fix` (`LocationFix`)

### failWith

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

Makes every later `locate` reject with a `LocationError` of this kind.

- `kind` (`LocationErrorKind`)

### holdNext

```ts
holdNext(): HeldCall<LocationFix>;
```

Holds the next `locate` until the handle settles it.

### locate

```ts
locate(options?: LocateOptions): Promise<LocationFix>;
```

Resolves with the scripted fix, rejects with the scripted failure, or waits for a hold. It rejects with `PortAbortError` when the signal fires.

- `options?` (`LocateOptions`)

### setFix

```ts
setFix(fix: LocationFix): void;
```

Changes the fix `locate` resolves with.

- `fix` (`LocationFix`)

## See also

- [`LocationProvider`](https://docs.mapcairn.com/api/core/LocationProvider.md)
- [`FakeLocationProviderOptions`](https://docs.mapcairn.com/api/core/FakeLocationProviderOptions.md)
- [`LocationFix`](https://docs.mapcairn.com/api/core/LocationFix.md)
- [`LocationErrorKind`](https://docs.mapcairn.com/api/core/LocationErrorKind.md)
- [`HeldCall`](https://docs.mapcairn.com/api/core/HeldCall.md)
- [`LocateOptions`](https://docs.mapcairn.com/api/core/LocateOptions.md)

Source: [packages/core/src/fakes/FakeLocationProvider.ts:46](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/fakes/FakeLocationProvider.ts#L46)
