Skip to main content

FakeSuggestionProvider

A scripted SuggestionProvider with no network and no timers.

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

Signature​

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

class FakeSuggestionProvider implements SuggestionProvider

Description​

How to script it:

  • setResults(query, results) answers one query; setDefaultResults answers every other query (empty by default). Queries are matched after trimming.
  • failWith(kind) makes every call reject with a SearchError until clearFailure().
  • holdNext() keeps the next 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.
  • suggestCalls records what the ui asked.

Properties​

suggestCalls​

readonly suggestCalls: RecordedSuggestCall[];

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

Methods​

clearFailure​

clearFailure(): void;

Stops FakeSuggestionProvider failing calls.

failWith​

failWith(kind: SearchErrorKind): void;

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

  • kind (SearchErrorKind)

holdNext​

holdNext(): HeldSuggestCall;

Holds the next call until the handle settles it.

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 suggestions for query (trimmed) with results.

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

suggest​

suggest(query: string, options?: SuggestOptions): 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? (SuggestOptions)

See also​

Source: packages/core/src/fakes/FakeSuggestionProvider.ts:39