Capacitor plugin mocking for Firebase Authentication integration tests
0 reputation · 14 Jun 2023, 17:55 UTC
Testing an Ionic Capacitor integration that uses Firebase Authentication without production credentials requires a stable mock for the native bridge.
Capacitor provides a plugin mocking API via capacitor.mock.ts files and the CLI generate command. Built-in mocks are documented for a subset of official plugins such as Camera, Geolocation and Filesystem. Authentication and payment plugins are reported to require production credentials for real flows and do not ship official mock implementations. The @capacitor/testing package offers MockPlugin utilities and createSyncPluginMock helpers, which are described as covering synchronous APIs. Ionic test utilities mock UI components but do not extend to Capacitor native bridge calls.
Capacitor 6 adds capacitor.config.ts plugin configuration typing, while mock registration still relies on manual patching of window.Capacitor.Plugins before test runner initialization. The desired behavior is a consistent, credential-free mock for async flows like OAuth redirects that matches plugin interfaces across versions.
Is there a standardized mock for @capacitor/firebase-authentication in Capacitor 6? Does @capacitor/testing support asynchronous OAuth redirect and token refresh scenarios? What permission boundary should govern mock registration timing relative to defineCustomElements and test runner startup?