> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Sharing and link fakes

Check the links the app opens, open the app with a link, run a shortcut or share to the app in a unit test. `import { openedURLs, openedAppSettings, openLink, runShortcut, receiveShare } from '@blotch/angular-lynx-testing-library';`

## Linking

Fakes [`LynxLinking`](/api/angular-lynx/sharing/linking.md) both ways: links the app opens, and links that open the app. The link that started the app is [`render()`](/api/testing-library/render.md#optionsinitialurl)'s `initialURL` option.

### `openedURLs()`

```typescript
function openedURLs(): readonly OpenedURL[];

type OpenedURL = { readonly url: string; readonly inApp: boolean };
```

The links the app opened with `LynxLinking` in this test, oldest first, so a spec can check where a tap leads. Each test starts with none.

```typescript
fireEvent.tap(screen.getByText('Help'));
await waitForUpdate();

expect(openedURLs()).toEqual([
  { url: 'https://example.com/help', inApp: true },
]);
```

- **`inApp`** is `true` for `openInApp()`, and `false` for `openURL()`.
- **Nothing opens.** Under the testing library, both resolve without opening anything.
- **`canOpenURL()`** resolves `true`.

### `openedAppSettings()`

```typescript
function openedAppSettings(): number;
```

How many times the app opened its own page in the phone's Settings with [`LynxLinking.openAppSettings()`](/api/angular-lynx/sharing/linking.md#lynxlinkingopenappsettings) in this test, so a spec can check that a refused permission's button leads there. Each test starts at 0.

```typescript
fireEvent.tap(screen.getByText('Open Settings'));
await waitForUpdate();

expect(openedAppSettings()).toBe(1);
```

- **Nothing opens.** Under the testing library, `openAppSettings()` resolves without opening anything.
- **`openedURLs()` doesn't list it:** Settings isn't a link.

### `openLink()`

```typescript
function openLink(url: string): void;
```

Opens the app with a link, so a spec can check where it leads. It's as if the person tapped a link with one of angular.json's [`deepLinkSchemes`](/guide/deep-links.md) while the app was open.

```typescript
await render(App, { providers: [provideRouter(routes)] });

openLink('myapp://orders/42');
await waitForUpdate();

expect(screen.getByText('Order 42')).toBeInTheDocument();
```

- **With `provideRouter()`**, the router navigates to the link's route.
- **Each [`LynxLinking.onURL()`](/api/angular-lynx/sharing/linking.md#lynxlinkingonurl) handler** is called with the URL.
- **It arrives through the [background thread](/guide/glossary.md#background-thread)**, as on a phone. Wait for it with `waitForUpdate()`.
- **Sent before the app listens**, it waits for the first handler, as a link that arrives while an app starts does.
- **It's never the link that started the app.** `getInitialURL()` stays `null`. Give that one to `render()` as [`initialURL`](/api/testing-library/render.md#optionsinitialurl).
- **Each test starts with none waiting.**

## Shortcuts

Runs the app's shortcuts for [`LynxShortcuts`](/api/angular-lynx/sharing/shortcuts.md).

### `runShortcut()`

```typescript
function runShortcut(id: string, options?: { readonly route?: string }): void;
```

Runs one of the app's [shortcuts](/guide/shortcuts.md), as the person does by asking Siri or from the app icon's menu. A spec can then check what the app does with it.

```typescript
await render(Feed);

runShortcut('refresh');
await waitForUpdate();

expect(screen.getByText('Refreshed')).toBeInTheDocument();
```

- **A spec doesn't read angular.json.** So `id` only has to be one the code under test handles with [`LynxShortcuts.on()`](/api/angular-lynx/sharing/shortcuts.md#lynxshortcutson).
- **`options.route`**: give a shortcut the `route` it has in angular.json here. The router then navigates to it.
- **It arrives through the background thread**, as on a phone. Wait for it with `waitForUpdate()`.
- **Run before the app has injected `LynxShortcuts`**, it waits, as the shortcut that starts an app does.
- **Each test starts with none waiting.**

## Share target

Shares to the app for [`LynxShareTarget`](/api/angular-lynx/sharing/share-target.md).

### `receiveShare()`

```typescript
function receiveShare(share: FakeShare): Promise<void>;

type FakeShare = {
  readonly text?: string;
  readonly url?: string;
  readonly title?: string;
  readonly files?: readonly { readonly blob: Blob; readonly name: string }[];
};
```

Shares to the app, as the person does by picking it in another app's share sheet. A spec can then check what the app does with what [`LynxShareTarget.onShare()`](/api/angular-lynx/sharing/share-target.md#lynxsharetargetonshare) hands it.

```typescript
await render(Inbox);

await receiveShare({ url: 'https://example.com/post/42', title: 'A post' });
await waitForUpdate();

expect(screen.getByText('A post')).toBeInTheDocument();
```

- **A spec doesn't read angular.json**, so any text, link or file arrives, whatever `shareTarget.mimeTypes` lists.
- **Each file's type** is its Blob's.
- **It arrives through the background thread.** Await `receiveShare()`, then `waitForUpdate()`.
- **Sent before the app registers a handler**, it waits, as the share that starts an app does.
- **Each test starts with none waiting.**

## Types

| Type        | Description                                   |
| ----------- | --------------------------------------------- |
| `OpenedURL` | One of `openedURLs()`: its `url`, and `inApp` |
| `FakeShare` | What `receiveShare()` takes                   |

## Related

- [Device fakes](/api/testing-library/fakes/index.md)
- [`LynxLinking`](/api/angular-lynx/sharing/linking.md)
- [`LynxShortcuts`](/api/angular-lynx/sharing/shortcuts.md)
- [`LynxShareTarget`](/api/angular-lynx/sharing/share-target.md)
- [Deep links](/guide/deep-links.md)
