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

Device fakes

Stand in for the phone in a unit test: go offline, tap an NFC tag, pick a photo, press back. Import each function from @blotch/angular-lynx-testing-library.

import {
  render,
  screen,
  setOnline,
  waitForUpdate,
} from '@blotch/angular-lynx-testing-library';

await render(Orders);

setOnline(false);
await waitForUpdate();

expect(
  screen.getByText('An internet connection is required'),
).toBeInTheDocument();

How they work

  • The setup fakes the native modules. A native module is the iOS or Android code behind a service such as LynxNfc. ng test loads the library's setup, which puts a fake in its place.
  • Await waitForUpdate() after a fake answers, before you check the screen. Many answers reach the app through the background thread, as on a phone.
  • Each test starts fresh. Each function says what a test starts with, such as a person who hasn't been asked for a permission yet.

Find a fake

ServiceFakes
LynxAppStatesetAppState()
LynxNetworksetOnline()
LynxBackButtonpressBackButton()
LynxBluetoothaddBluetoothDevice(), setBluetoothState()
LynxNfctapNfcTag(), failNfcSession(), setNfcState(), nfcSession(), nfcWrites()
LynxWifisetWifiNetwork(), denyWifiNetworkRead(), allowWifiNetworkRead(), queueWifiJoinResult(), wifiJoins(), wifiLeaves()
LynxGeolocationsetLocation(), setLocationPermission(), setLocationAlways(), setLocationAnswer(), setLocationAlwaysAnswer(), setLocationEnabled(), locationPrompts()
LynxMotionemitMotion(), setHeading(), shakeDevice()
LynxBiometricssetBiometrics(), queueBiometricResult(), biometricPrompts(). LynxSecureStorage's requireBiometrics uses them too
LynxBarcodeScannerqueueBarcodeScan(), cancelBarcodeScan(), failBarcodeScan()
LynxAudioRecordersetMicrophonePermission(), setRecordedAudio(), emitAudioLevel(), interruptAudioRecording(), failAudioRecording(), audioRecording()
LynxAudioPlayersetAudioFile(), audioPlayback(), pressRemoteCommand(), interruptAudioPlayback(), failAudioPlayback()
LynxImagePickersetPickedImage(), setTakenPhoto(), failImagePicker(), imagePickerRequests()
LynxPhotoLibrarysavedPhotos(), setPhotoLibraryPermission()
LynxFilePickersetPickedFiles(), setFilePickerCanceled(), savedFiles()
LynxContactsanswerContactPicker(), failContactPicker(), contactPicker(), addContact(), setContactsPermission()
LynxCalendarcalendarEvents(), answerCalendarSheet(), failCalendarSheet()
LynxLinkingopenedURLs(), openedAppSettings(), openLink(). render()'s initialURL too
LynxShortcutsrunShortcut()
LynxShareTargetreceiveShare()
LynxAppleSignInsetAppleSignInResult(), setAppleSignInError(), setAppleSignInAvailable(), setAppleCredentialState(), appleSignInRequests()
LynxStoreReviewreviewRequests()
LynxTrackingsetTrackingStatus(), setTrackingAnswer(), trackingPrompts()

Pages

PageServices
Device and hostApp state, network, Android's back button
Bluetooth, NFC and Wi-FiBluetooth LE devices, NFC tags, Wi-Fi networks
Sensors and audioLocation, motion, biometrics, audio recorder, audio player
Camera, photos and filesImage picker, barcode scanner, photo library, file picker
Contacts and calendarThe address book, the contact picker, the calendar's event editor
Sharing and linksOpened links, incoming links, shortcuts, shares to the app
Sign-in, reviews and trackingSign in with Apple, store reviews, tracking