Skip to main content

FakeSearchProvider

A scripted SearchProvider with no network and no timers.

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

Signature​

import { FakeSearchProvider } from "@mapcairn/core";

class FakeSearchProvider implements SearchProvider

Description​

How to script it:

  • setResults(query, results) answers one query; setDefaultResults answers every other query (empty by default). Queries are matched after trimming.
  • setReverseResult(result | null) answers every reverse call.
  • failWith(kind) makes every call reject with a SearchError until clearFailure().
  • holdNext() keeps the next search or reverse call pending until the returned handle resolves or rejects it. Holds queue in order.
  • A blank query resolves to an empty array without using any script.
  • Every call honours its AbortSignal by rejecting with PortAbortError.
  • searchCalls and reverseCalls record what the ui asked.

Properties​

reverseCalls​

readonly reverseCalls: RecordedReverseCall[];

Every reverse call, in order, with its position and options.

searchCalls​

readonly searchCalls: RecordedSearchCall[];

Every search call, in order, with its query and options.

Methods​

clearFailure​

clearFailure(): void;

Stops FakeSearchProvider failing calls.

failWith​

failWith(kind: SearchErrorKind): void;

Makes every later call reject with a SearchError of this kind.

  • kind (SearchErrorKind)

holdNext​

holdNext(): HeldSearchCall;

Holds the next call (search or reverse) until the handle settles it.

reverse​

reverse(position: LatLng, options?: Pick<SearchOptions, "signal">): Promise<SearchResult | null>;

Answers with the scripted reverse result, or null.

  • position (LatLng)
  • options? (Pick<SearchOptions, "signal">)
search(query: string, options?: SearchOptions): Promise<readonly SearchResult[]>;

Answers with the results scripted for the trimmed query, or the default results. A blank query resolves to an empty list without using any script.

  • query (string)
  • options? (SearchOptions)

setDefaultResults​

setDefaultResults(results: readonly SearchResult[]): void;

Answers every query that has no specific script.

  • results (readonly SearchResult[])

setResults​

setResults(query: string, results: readonly SearchResult[]): void;

Answers searches for query (trimmed) with results.

  • query (string)
  • results (readonly SearchResult[])

setReverseResult​

setReverseResult(result: SearchResult | null): void;

Sets what reverse finds. null means there is no place there.

  • result (SearchResult | null)

See also​

Source: packages/core/src/fakes/FakeSearchProvider.ts:56