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/device.md.

Device and host fakes

Send the app to the background, take the phone offline, or press Android's back button in a unit test. import { setAppState, setOnline, pressBackButton } from '@blotch/angular-lynx-testing-library';

App state

Fakes what LynxAppState reports. Each test starts 'active'.

setAppState()

function setAppState(state: 'active' | 'inactive' | 'background'): void;

Sends the app to the background, or brings it back, as the person does by leaving the app and returning. A spec can then check what the app does on its return.

await render(Schedule);

setAppState('background');
await waitForUpdate();
vi.setSystemTime(new Date('2026-01-02T09:00'));
setAppState('active');
await waitForUpdate();

expect(screen.getByText('Today: 2 January')).toBeInTheDocument();
  • LynxAppState.state() becomes state, and active() is true only for 'active'.
  • 'inactive' is an app on screen that isn't taking touches, such as with Control Center pulled over it, or a call coming in.
  • It arrives as a change to the host's global props, as on a phone. Wait for it with waitForUpdate().
  • Wait between two states too. Otherwise an effect() runs once for both, and never sees the app leave.

Network

Fakes what LynxNetwork reports. Each test starts online.

setOnline()

function setOnline(online: boolean): void;

Takes the phone offline, or brings it back online. A spec can then check what the app shows without a connection, and what it does once it's back.

await render(Orders);

setOnline(false);
await waitForUpdate();

expect(
  screen.getByText('An internet connection is required'),
).toBeInTheDocument();
  • LynxNetwork.online() becomes online.
  • It arrives as a change to the host's global props, as on a phone. Wait for it with waitForUpdate().
  • Wait between two changes too. Otherwise an effect() runs once for both, and never sees the phone go offline.
  • It changes only what LynxNetwork reports. Requests go on as the spec's fakes answer them.

Back button

Presses Android's back button for LynxBackButton and the router. Each test starts with back left to Android.

pressBackButton()

function pressBackButton(): boolean;

Presses Android's back button, so a spec can check what the app does with it. The app may close what's open on top, with a handler registered with LynxBackButton.on(). Or it may go back a screen through the router.

await render(Search);
fireEvent.tap(screen.getByText('Search'));
await waitForUpdate();

expect(pressBackButton()).toBe(true);
await waitForUpdate();

expect(screen.queryByText('Results')).toBeNull();
  • It returns false when the app doesn't take back. As on Android, the press reaches the app only while the app takes back. Otherwise Android would leave the app.
  • It arrives through the background thread, as on a phone. Wait for it with waitForUpdate().
  • An <overlay> takes back before the app on a phone. Fire its requestclose event for that instead.

Types

TypeDescription
AppStateWhat setAppState() takes: 'active', 'inactive' or 'background'