# FakeSuggestionProvider

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

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

## Signature

```ts
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

```ts
readonly suggestCalls: RecordedSuggestCall[];
```

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

## Methods

### clearFailure

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

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

### failWith

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

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

- `kind` (`SearchErrorKind`)

### holdNext

```ts
holdNext(): HeldSuggestCall;
```

Holds the next call until the handle settles it.

### setDefaultResults

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

Answers every query that has no specific script.

- `results` (`readonly SearchResult[]`)

### setResults

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

Answers suggestions for `query` (trimmed) with `results`.

- `query` (`string`)
- `results` (`readonly SearchResult[]`)

### suggest

```ts
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

- [`SuggestionProvider`](https://docs.mapcairn.com/api/core/SuggestionProvider.md)
- [`SearchErrorKind`](https://docs.mapcairn.com/api/core/SearchErrorKind.md)
- [`HeldSuggestCall`](https://docs.mapcairn.com/api/core/HeldSuggestCall.md)
- [`SearchResult`](https://docs.mapcairn.com/api/core/SearchResult.md)
- [`SuggestOptions`](https://docs.mapcairn.com/api/core/SuggestOptions.md)
- [`RecordedSuggestCall`](https://docs.mapcairn.com/api/core/RecordedSuggestCall.md)

Source: [packages/core/src/fakes/FakeSuggestionProvider.ts:39](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/fakes/FakeSuggestionProvider.ts#L39)
