cometchat-native-testing
Testing patterns for CometChat React Native — Jest + React Native Testing Library setup, mocking the UI Kit + SDK, testing custom bubbles / headers / composer actions, snapshot pitfalls, E2E with Detox vs Maestro, and CI integration. Covers what to test vs what to skip.
cometchat · AI review on file
Installation
Read the source and dependencies before running a command. Copying does not install or execute anything.
npx skills add cometchat/cometchat-skills --skill cometchat-native-testingAbout this skill
name: cometchat-native-testing description: "Testing patterns for CometChat React Native — Jest + React Native Testing Library setup, mocking the UI Kit + SDK, testing custom bubbles / headers / composer actions, snapshot pitfalls, E2E with Detox vs Maestro, and CI integration. Covers what to test vs what to skip." license: "MIT" compatibility: "Node.js >=18; React Native >=0.70; @cometchat/chat-uikit-react-native ^5; Jest ^29; @testing-library/react-native ^12" allowed-tools: "executeBash, readFile, fileSearch, listDirectory" metadata: author: "CometChat" version: "1.0.0" tags: "cometchat react-native testing jest rnt detox maestro ci"
Purpose
Teaches Claude how to write and run tests against a CometChat React Native integration. Covers:
- Unit / component tests with Jest + React Native Testing Library (RNTL)
- How to mock
@cometchat/chat-uikit-react-nativeand@cometchat/chat-sdk-react-native(both pull in native modules that fail in Node's jest-expo / jest-react-native environments) - Testing custom bubbles, headers, composer actions, empty states
- Snapshot testing pitfalls specific to theme-driven components
- E2E with Detox (iOS + Android native drivers) vs Maestro (declarative YAML)
- Which tests catch real regressions vs which are flaky churn
Ground truth: @cometchat/chat-uikit-react-native@5.3.3's example jest config (examples/SampleAppWithPushNotifications/jest.config.js) and the standard RN testing toolkit docs (callstack.github.io/react-native-testing-library, wix.github.io/Detox, maestro.mobile.dev).
1. What to test, what to skip
Not every test is worth the maintenance cost. A few rules of thumb:
Worth testing:
- Custom components you wrote (custom bubble, custom header, empty-state view)
- Navigation logic triggered by CometChat events (push tap → deep-link)
- Message render logic with text formatters
- Your provider chain wires correctly (four-wrapper order, init called, login called)
- Production auth token refresh + retry logic
- User-ID mapping (Firebase UID → CometChat UID)
Skip:
- UI Kit internals — that's the UI Kit's responsibility. Testing
<CometChatConversations>renders a list is testing CometChat's code. - Realtime delivery (A sends, B receives) — requires real servers; flaky and slow; use manual QA or E2E with real accounts.
- Presence / typing indicators — race-prone, depend on socket state.
- Snapshot tests of CometChat components — theme changes, UI Kit updates, and
cometchat-native-themingedits all churn the snapshots with no real signal. - Native module calls (camera, picker) — Jest's mocks already return stubs; testing them verifies the mock, not the integration.
The golden rule: if the test fails because your code changed, it's valuable. If it fails because the UI Kit updated or a network blip happened, it's churn.
2. Toolchain
| Layer | Tool | Why |
|---|---|---|
| Unit + component tests | Jest + @testing-library/react-native | The RN default. Preset handles metro module resolution. |
| Mocking | Jest moduleNameMapper + manual mocks | UI Kit imports native modules — can't run real components in a Node env. |
| Snapshot | Jest's built-in | Use sparingly — see §7 |
| E2E | Maestro OR Detox | See §10 for tradeoff |
| CI | GitHub Actions / EAS / Bitrise | §11 |
Install:
# Bare RN
npm install --save-dev jest @testing-library/react-native @testing-library/jest-native \
react-test-renderer @types/jest
# Expo
npx expo install --dev jest-expo @testing-library/react-native @testing-library/jest-native \
react-test-renderer
jest-expo wraps react-native preset with Expo-specific module resolution (handles expo-modules-core, expo-router, etc.).
3. Jest config
Bare RN — jest.config.js:
module.exports = {
preset: "react-native",
setupFilesAfterEach: ["<rootDir>/jest.setup.ts"],
transformIgnorePatterns: [
"node_modules/(?!(?:react-native|@react-native|@react-navigation|" +
"@cometchat/chat-uikit-react-native|@cometchat/chat-sdk-react-native|" +
"react-native-.+|@notifee/react-native)/)",
],
moduleNameMapper: {
"^@cometchat/chat-uikit-react-native$": "<rootDir>/__mocks__/cometchat-uikit.ts",
"^@cometchat/chat-sdk-react-native$": "<rootDir>/__mocks__/cometchat-sdk.ts",
},
};
Expo — jest.config.js:
module.exports = {
preset: "jest-expo",
setupFilesAfterEach: ["<rootDir>/jest.setup.ts"],
transformIgnorePatterns: [
"node_modules/(?!(?:(jest-)?react-native|@react-native|expo(nent)?|@expo(nent)?/.*|" +
"@expo-google-fonts/.*|react-navigation|@react-navigation/.*|" +
"@cometchat/chat-uikit-react-native|@cometchat/chat-sdk-react-native|" +
"@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)/)",
],
moduleNameMapper: {
"^@cometchat/chat-uikit-react-native$": "<rootDir>/__mocks__/cometchat-uikit.ts",
"^@cometchat/chat-sdk-react-native$": "<rootDir>/__mocks__/cometchat-sdk.ts",
},
};
transformIgnorePatterns matters. By default Jest doesn't transform anything under node_modules, but CometChat ships ES module source. Without the pattern, Jest errors with SyntaxError: Unexpected token 'export'. The UI Kit + SDK names must be in the allow list.
4. Global setup — jest.setup.ts
import "@testing-library/jest-native/extend-expect";
// Silence RN's "AnimatedValue" warning noise in tests
jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper");
// Mock native modules that the UI Kit pulls in
jest.mock("react-native-gesture-handler", () => {
const View = require("react-native/Libraries/Components/View/View");
return {
GestureHandlerRootView: View,
PanGestureHandler: View,
TapGestureHandler: View,
State: {},
Directions: {},
};
});
jest.mock("react-native-reanimated", () =>
require("react-native-reanimated/mock"),
);
jest.mock("react-native-safe-area-context", () => ({
SafeAreaProvi
Read the complete source ↗