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

Sign-in, review and tracking fakes

Sign in with Apple, count rating requests, or answer the tracking prompt in a unit test. import { setAppleSignInResult, reviewRequests, setTrackingStatus } from '@blotch/angular-lynx-testing-library';

Sign in with Apple

Fakes LynxAppleSignIn's native module.

  • Each test starts with the sheet there, no sign-ins and no users.
  • Until a spec answers, the person closes the sheet, and signIn() rejects with canceled.
  • The answer reaches the app through the background thread, as on a phone. Wait for it with waitForUpdate().
setAppleSignInResult({ user: 'u1', email: 'ada@example.com' });
await render(SignIn);

fireEvent.tap(screen.getByText('Sign in with Apple'));
await waitForUpdate();

expect(screen.getByText('Signed in as ada@example.com')).toBeInTheDocument();
expect(appleSignInRequests()).toEqual([{ scopes: ['email', 'fullName'] }]);

setAppleSignInResult()

function setAppleSignInResult(result?: FakeAppleSignInResult): void;

Has the person sign in from now on in this test: signIn() resolves with result.

  • email and fullName are shared only when the sign-in asks for their scopes, as Apple does.
  • What's left out takes a test value. user is test-apple-user, and the tokens are test-identity-token and test-authorization-code.
  • Each user it signs in is authorized afterwards.

setAppleSignInError()

function setAppleSignInError(
  code: 'canceled' | 'failed',
  message?: string,
): void;

Has the next sign-ins reject with code.

setAppleSignInAvailable()

function setAppleSignInAvailable(available: boolean): void;

false takes the native sheet away, as on Android and the web.

  • isAvailable() resolves false, and signIn() rejects with unsupported.
  • An <apple-sign-in-button> made after it is the one the runtime draws, rather than iOS's element. getByText() finds its title.

setAppleCredentialState()

function setAppleCredentialState(
  user: string,
  state: 'authorized' | 'revoked' | 'notFound' | 'transferred',
): void;

Sets what getCredentialState(user) resolves with. A user nobody signed in is notFound.

appleSignInRequests()

function appleSignInRequests(): readonly AppleSignInRequest[];

Lists the sign-ins the app opened, with the scopes, nonce and state each asked for.

Store review

Counts the rating requests LynxStoreReview makes.

reviewRequests()

function reviewRequests(): number;

How many times the app asked for a rating with LynxStoreReview.request() in this test. A spec can check it asks at the right moment, and only then.

fireEvent.tap(screen.getByText('Place order'));
await waitForUpdate();

expect(reviewRequests()).toBe(1);
  • request() resolves without showing anything.
  • Each test starts at 0.

Tracking

Fakes whether the app may track the person, for LynxTracking. Each test starts at notDetermined.

setTrackingStatus()

function setTrackingStatus(status: FakeTrackingStatus): void;

Sets whether the app may track the person, as if they'd answered the prompt or changed it in Settings. It's what status() reads, and what requestPermission() resolves with.

FakeTrackingStatus takes the same values as TrackingStatus.

LynxTracking reads the status when it's created, and again when the app comes back to the foreground. So set it before render():

setTrackingStatus('denied');
await render(Feed);

expect(screen.getByText('Ads that respect your choice')).toBeInTheDocument();

Or, after render(), follow it with setAppState('background') and setAppState('active'), as a person coming back from Settings would. Await waitForUpdate() after each. Without the wait between them, the app never seems to leave, and the status isn't read again:

setTrackingStatus('denied');
setAppState('background');
await waitForUpdate();
setAppState('active');
await waitForUpdate();

expect(screen.getByText('Ads that respect your choice')).toBeInTheDocument();

setTrackingAnswer()

function setTrackingAnswer(answer: 'authorized' | 'denied'): void;

What the person answers when requestPermission() shows the prompt: authorized by default. The prompt shows only while the status is notDetermined.

trackingPrompts()

function trackingPrompts(): number;

How many times requestPermission() showed the prompt in this test. A spec can check the app asks at the right moment, and only once. Each test starts at 0.

setTrackingAnswer('denied');
fireEvent.tap(screen.getByText('Continue'));
await waitForUpdate();

expect(trackingPrompts()).toBe(1);

Types

TypeDescription
FakeAppleSignInResultWhat setAppleSignInResult() takes: user, the tokens, email, fullName and realUserStatus
FakeAppleCredentialStateWhat setAppleCredentialState() takes
AppleSignInRequestOne of appleSignInRequests(): scopes, nonce and state
FakeTrackingStatusWhat setTrackingStatus() takes, the same values as TrackingStatus