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 whatlocateresolves with.failWith(kind)makeslocatereject with aLocationErroruntilclearFailure().holdNext()keeps the nextlocatepending until the handle settles it.- With
supportsWatch,watchregisters handlers, andemitFixandemitErrorpush to every active watcher. A watcher stops when its signal aborts. WithoutsupportsWatch,watchisundefined. - Every
locatehonours its signal by rejecting withPortAbortError. locateCallsrecords the options andwatcherCountthe 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)