Deeplink Testing
The service provides the ability to test custom protocol handlers and deeplinks in your Tauri application using the browser.tauri.triggerDeeplink() method.
Overview
What is Deeplink Testing?
Deeplink testing allows you to verify that your Tauri application correctly handles custom protocol URLs (e.g., myapp://action?param=value). This is essential when your app registers as a protocol handler and needs to respond to URLs opened from external sources.
When Should You Use It?
Use browser.tauri.triggerDeeplink() when you need to:
- Test that your app correctly handles custom protocol URLs
- Verify deeplink parameter parsing and routing logic
- Test protocol handler registration and activation
- Validate deeplink-driven workflows in your application
Prerequisites
Tauri Deep Link Plugin
Your Tauri app must have the @tauri-apps/plugin-deep-link plugin installed and configured. See the official Tauri deep linking documentation for setup instructions.
Protocol Registration
Your app must register its custom protocol scheme in tauri.conf.json under the deep-link plugin configuration:
{
"plugins": {
"deep-link": {
"desktop": {
"schemes": ["myapp"]
}
}
}
}
Basic Usage
Simple Example
describe('Protocol Handler Tests', () => {
it('should handle custom protocol deeplinks', async () => {
await browser.tauri.triggerDeeplink('myapp://open?file=test.txt');
await browser.waitUntil(async () => {
const openedFile = await browser.tauri.execute(() => {
return globalThis.lastOpenedFile;
});
return openedFile === 'test.txt';
}, {
timeout: 5000,
timeoutMsg: 'App did not handle the deeplink'
});
});
});
Complex URL Parameters
it('should preserve query parameters', async () => {
await browser.tauri.triggerDeeplink(
'myapp://action?param1=value1¶m2=value2&array[]=a&array[]=b'
);
const receivedParams = await browser.tauri.execute(() => {
return globalThis.lastDeeplinkParams;
});
expect(receivedParams.param1).toBe('value1');
expect(receivedParams.param2).toBe('value2');
expect(receivedParams.array).toEqual(['a', 'b']);
});
Error Handling
it('should reject invalid protocols', async () => {
await expect(
browser.tauri.triggerDeeplink('https://example.com')
).rejects.toThrow('Invalid deeplink protocol');
});
it('should reject malformed URLs', async () => {
await expect(
browser.tauri.triggerDeeplink('not a url')
).rejects.toThrow('Invalid deeplink URL');
});
Platform Behavior
The service handles platform-specific differences automatically:
Windows
- Uses
cmd /c startcommand to trigger the deeplink - No URL modification needed
macOS
- Uses
opencommand to trigger the deeplink - No URL modification needed