# FakeFileOpener

A scripted [`FileOpener`](https://docs.mapcairn.com/api/core/FileOpener.md) that plays the person at the picker.

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

## Signature

```ts
import { FakeFileOpener } from "@mapcairn/core";
 
class FakeFileOpener implements FileOpener
```

## Description

How to script it: `open` waits, as a real picker does, until `choose(file)`
or `cancel()` settles it. `failWith("unsupported")` makes later opens
reject at once, `failWith("unreadable")` makes a chosen file unreadable,
and `succeed()` clears either. A chosen file's size is its length in
characters. `opens` records the options of every call and `waiting` says
whether a picker is open. It rejects only with `FileOpenError`.

## Properties

### opens

```ts
readonly opens: FileOpenOptions[];
```

The options of every `open` call, in order.

### waiting

```ts
readonly get waiting(): boolean;
```

Whether a picker is open and waiting for the person.

## Methods

### cancel

```ts
cancel(): void;
```

The person closes the open picker without choosing.

### choose

```ts
choose(file: OpenedFile): void;
```

The person chooses `file` in the open picker. Does nothing when none is open.

- `file` (`OpenedFile`)

### failWith

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

Makes later opens fail this way.

- `kind` (`FakeFileOpenFailure`)

### open

```ts
open(options: FileOpenOptions): Promise<OpenedFile>;
```

Waits, as a real picker does, until `choose` or `cancel` settles it. It rejects at once when `failWith("unsupported")` is scripted.

- `options` (`FileOpenOptions`)

### succeed

```ts
succeed(): void;
```

Makes later opens work again.

## See also

- [`FileOpener`](https://docs.mapcairn.com/api/core/FileOpener.md)
- [`OpenedFile`](https://docs.mapcairn.com/api/core/OpenedFile.md)
- [`FakeFileOpenFailure`](https://docs.mapcairn.com/api/core/FakeFileOpenFailure.md)
- [`FileOpenOptions`](https://docs.mapcairn.com/api/core/FileOpenOptions.md)

Source: [packages/core/src/fakes/FakeFileOpener.ts:29](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/fakes/FakeFileOpener.ts#L29)
