by @cap-go
Complete testing guide for Capacitor apps covering unit tests, integration tests, E2E tests, and native testing. Includes Jest, Vitest, Playwright, Appium, and native testing frameworks. Use this skill when users need to test their mobile apps.
Comprehensive testing strategies for Capacitor mobile apps.
/\
/ \ E2E Tests (Few)
/----\ - Real devices
/ \ - Full user flows
/--------\ Integration Tests (Some)
/ \ - Component interactions
/------------\ - API integration
/ \ Unit Tests (Many)
/----------------\ - Pure functions
- Business logic
bun add -D vitest @vitest/coverage-v8
// vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
},
setupFiles: ['./src/test/setup.ts'],
},
});
// src/test/setup.ts
import { vi } from 'vitest';
// Mock @capacitor/core
vi.mock('@capacitor/core', () => ({
Capacitor: {
isNativePlatform: vi.fn(() => true),
getPlatform: vi.fn(() => 'ios'),
isPluginAvailable: vi.fn(() => true),
},
registerPlugin: vi.fn(),
}));
// Mock @capacitor/preferences
vi.mock('@capacitor/preferences', () => ({
Preferences: {
get: vi.fn(),
set: vi.fn(),
remove: vi.fn(),
clear: vi.fn(),
},
}));
// Mock @capgo/capacitor-native-biometric
vi.mock('@capgo/capacitor-native-biometric', () => ({
NativeBiometric: {
isAvailable: vi.fn().mockResolvedValue({
isAvailable: true,
biometryType: 'touchId',
}),
verifyIdentity: vi.fn().mockResolvedValue({}),
setCredentials: vi.fn().mockResolvedValue({}),
getCredentials: vi.fn().mockResolvedValue({
username: 'test@example.com',
password: 'token',
...