Testing
Test keys, SDK logs, terminal commands that open links, the dashboard Debugger and Jest tests for your routing.
Use the test environment
Build development versions of your app with a pk_test_ key and create test links for them. Test links, test installs and test events stay out of your live analytics. Switch the dashboard to the test environment to create and inspect them. See Environments.
Remember that resolving follows the key: a live link opened by an app using a pk_test_ key comes back unresolved, and the other way round.
Turn on logging
Lander.initialize({ apiKey: 'pk_test_...', enableLogging: __DEV__ })The SDK then prints what it does with console.log, prefixed with [Lander], so the lines show up in Metro, React Native DevTools, Xcode and adb logcat. It never logs your API key. Lines you will see:
| Log line | Meaning |
|---|---|
Created install ID ... | First launch (or a reset install). A new random ID was stored. |
Init ok | The launch report reached Lander. Events can be sent from now on. |
Init failed: LanderError(invalid_api_key, 401): ... | The key is wrong or revoked. |
Unsupported platform, skipping init. ... | No native module (Expo Go, or the app was not rebuilt), or a platform other than iOS and Android. |
Deferred link: LanderLink(...) | The first launch report returned a deferred link. |
Resolved LanderLink(...) | A link was resolved. The line shows its ID, path, params, URL, confidence and method. |
Not a Lander link: https://... | Lander answered 404 for this URL. It is still delivered, unresolved. |
Resolve failed for https://...: LanderError(...) | Network error, timeout, or the link is disabled or expired (410). Delivered unresolved. |
Ignoring duplicate link ... | The same URL arrived twice within 2 seconds. |
Sent 3 events | A batch of events was accepted. |
Event batch failed (network_error), retrying in 2s | The queue will try again with backoff. |
Event batch rejected (...): check the API key. Pausing until next launch. | A 401 or 403 on events. Events are kept for the next launch. |
Install ID belongs to another project, creating a new one | You switched keys between test and live (or projects). Harmless. |
Open links from the terminal
You do not need to tap links in Notes or Messages to test. These commands deliver a URL to your app exactly as a tap would.
# Universal Link (needs the apple-app-site-association file to be fetched)
xcrun simctl openurl booted "https://acme.golander.link/p-123"
# Custom scheme (always opens the app; good for testing routing)
xcrun simctl openurl booted "acmeshop://product/123"
# Cold start: stop the app first, then open the link
xcrun simctl terminate booted com.acme.shop
xcrun simctl openurl booted "https://acme.golander.link/p-123"Run each link twice: once with the app in the background (warm start) and once after stopping it (cold start). Both should land on the same screen, once. In a debug build a cold start also waits for Metro to serve the bundle; the link is kept until your listener subscribes.
On a real iPhone, paste the link into Notes or Messages and tap it. Typing a Universal Link into Safari's address bar does not open the app; that is iOS behavior, not a setup problem.
Test a first launch
A first launch is what produces a deferred link and an install. Uninstalling removes the install ID, so a reinstall is a fresh first launch:
xcrun simctl uninstall booted com.acme.shop # iOS Simulator
adb uninstall com.acme.shop # AndroidWays to see a deferred link while developing:
- Authenticated handoff (any device): create a handoff with your
sk_test_key for a test user, sign in as that user in the app and callLander.claimHandoff. See Authenticated handoff. - iOS Continue in app page (real device, with
iosLandingPageon): delete the app, tap a test link in Safari, install your build from Xcode instead of the App Store, go back to Safari and tap I already have the app, open it. - Android install referrer: needs a real install from Google Play, so
npx react-native run-android,npx expo run:androidand sideloaded APKs never get one.
Check everything with the Debugger
Open Build > Debugger in the dashboard and paste a link. It checks everything between a tap and your app's screen, in four groups: the link itself, your app configuration (Team ID and bundle ID, package name and fingerprints), the domain files on the edge (apple-app-site-association and assetlinks.json), and whether an app with the SDK has reported in the last 24 hours. Failed checks link to the fix.
Build > SDK shows the SDK versions that apps report in the current environment, so you can confirm a new build is talking to Lander. React Native apps report as react-native/0.1.1.
Unit test your routing
LanderLink.create and LanderLink.unresolved build links without a device or the network, so you can test how your app routes them with Jest:
import { LanderLink } from 'react-native-lander'
import { screenFor } from '../src/routing'
test('a resolved link routes to its path', () => {
const link = LanderLink.create({
url: 'https://acme.golander.link/p-123',
linkId: '0b8f9a52-6f1c-4d3e-9a43-3f0d2b7c1e55',
shortUrl: 'https://acme.golander.link/p-123',
path: '/product/123',
params: { productId: '123' },
confidence: 'deterministic',
method: 'universal_link',
})
expect(link.isResolved).toBe(true)
expect(link.route).toBe('/product/123')
expect(screenFor(link)).toEqual({ name: 'Product', params: { id: '123', link } })
})
test('a custom scheme URL routes without Lander', () => {
const link = LanderLink.unresolved('acmeshop://product/123?color=red')
expect(link.isResolved).toBe(false)
expect(link.route).toBe('/product/123?color=red')
})Here screenFor stands for your own function that maps a link to a screen, like openLink in Receiving links.
The package's main entry loads its native module, so Jest suites that render components which import react-native-lander should mock it. Keep the real LanderLink helpers and replace the rest:
jest.mock('react-native-lander', () => {
const actual = jest.requireActual('react-native-lander')
const listeners = new Set<(link: unknown) => void>()
return {
...actual,
Lander: {
initialize: jest.fn(async () => {}),
onDeepLink: (listener: (link: unknown) => void) => {
listeners.add(listener)
return { remove: () => listeners.delete(listener) }
},
getInitialLink: jest.fn(async () => null),
createLink: jest.fn(),
claimHandoff: jest.fn(async () => null),
trackEvent: jest.fn(async () => {}),
installId: null,
},
useLanderDeepLink: (listener: (link: unknown) => void) => {
const React = jest.requireActual('react')
React.useEffect(() => {
listeners.add(listener)
return () => {
listeners.delete(listener)
}
}, [listener])
},
// Tests call this to simulate a tap.
__sendLink: (link: unknown) => listeners.forEach((l) => l(link)),
}
})import { act, render, screen } from '@testing-library/react-native'
import { LanderLink } from 'react-native-lander'
import App from '../App'
const { __sendLink } = jest.requireMock('react-native-lander')
test('opens the product screen from a link', async () => {
render(<App />)
await act(async () => __sendLink(LanderLink.unresolved('acmeshop://product/123')))
expect(await screen.findByText('Product 123')).toBeTruthy()
})If you prefer no module mock, let your root component take the subscribe function as an optional prop that defaults to Lander.onDeepLink, and pass your own in tests.
The example app
The SDK ships with Acme Shop, in the example folder of the source repository: a small app with a product screen at /product/:id that shows what Lander resolved for each link, creates share links with createLink and tracks purchases with trackEvent. Its bundle ID and package name are com.acme.shop and its custom scheme is acmeshop. It is set up to run against a local copy of the Lander monorepo (below) with the seeded demo key, so for most teams it is best read as reference code. The seeded link https://acme.golander.link/p-123 resolves to /product/123.
Against a local Lander API
This is for working on Lander's own monorepo. With it running (pnpm dev), the API listens on port 8787 and a seeded test key exists:
import { Platform } from 'react-native'
Lander.initialize({
apiKey: 'pk_test_DemoPublishableKey000000000000',
baseUrl: Platform.OS === 'android' ? 'http://10.0.2.2:8787' : 'http://localhost:8787',
enableLogging: true,
})The Android emulator reaches your computer at 10.0.2.2; the iOS Simulator shares its localhost. Plain HTTP needs cleartext traffic allowed on Android and NSAllowsLocalNetworking on iOS, which React Native's templates already allow in debug builds. Locally, link URLs on localhost, 127.0.0.1 or 10.0.2.2 resolve as acme.golander.link.