Skip to main content

FakeLocationProvider

A scripted LocationProvider with no geolocation and no timers.

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

Signature​

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)​

constructor(options?: FakeLocationProviderOptions);

Constructs a new instance of the FakeLocationProvider class

  • options? (FakeLocationProviderOptions)

Properties​

locateCalls​

readonly locateCalls: (LocateOptions | undefined)[];

The options of every locate call, in order.

supportsWatch​

readonly supportsWatch: boolean;

Whether watch exists, as the constructor option set it.

watch​

readonly watch?: LocationProvider["watch"];

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

watcherCount​

readonly get watcherCount(): number;

The number of watchers that have not been aborted.

Methods​

clearFailure​

clearFailure(): void;

Stops FakeLocationProvider failing calls.

emitError​

emitError(error: Error): void;

Delivers an error to every active watcher.

  • error (Error)

emitFix​

emitFix(fix: LocationFix): void;

Delivers a fix to every active watcher.

  • fix (LocationFix)

failWith​

failWith(kind: LocationErrorKind): void;

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

  • kind (LocationErrorKind)

holdNext​

holdNext(): HeldCall<LocationFix>;

Holds the next locate until the handle settles it.

locate​

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​

setFix(fix: LocationFix): void;

Changes the fix locate resolves with.

  • fix (LocationFix)

See also​

Source: packages/core/src/fakes/FakeLocationProvider.ts:46