For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/testing-library/fakes/sharing.md.

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 both ways: links the app opens, and links that open the app. The link that started the app is render()'s initialURL option.

openedURLs()

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.

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()

function openedAppSettings(): number;

How many times the app opened its own page in the phone's Settings with LynxLinking.openAppSettings() in this test, so a spec can check that a refused permission's button leads there. Each test starts at 0.

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.
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 while the app was open.

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() handler is called with the URL.
  • It arrives through the 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.
  • Each test starts with none waiting.

Shortcuts

Runs the app's shortcuts for LynxShortcuts.

runShortcut()

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

Runs one of the app's shortcuts, 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.

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().
  • 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.

receiveShare()

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() hands it.

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

TypeDescription
OpenedURLOne of openedURLs(): its url, and inApp
FakeShareWhat receiveShare() takes