@cometchat/skills 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -17
  3. package/bin/install.js +389 -43
  4. package/package.json +19 -9
  5. package/skills/cometchat/SKILL.md +1066 -265
  6. package/skills/cometchat-android-v5/SKILL.md +120 -0
  7. package/skills/cometchat-android-v5-components/SKILL.md +430 -0
  8. package/skills/cometchat-android-v5-core/SKILL.md +468 -0
  9. package/skills/cometchat-android-v5-customization/SKILL.md +305 -0
  10. package/skills/cometchat-android-v5-extensions/SKILL.md +124 -0
  11. package/skills/cometchat-android-v5-features/SKILL.md +130 -0
  12. package/skills/cometchat-android-v5-placement/SKILL.md +276 -0
  13. package/skills/cometchat-android-v5-production/SKILL.md +94 -0
  14. package/skills/cometchat-android-v5-push/SKILL.md +620 -0
  15. package/skills/cometchat-android-v5-testing/SKILL.md +187 -0
  16. package/skills/cometchat-android-v5-theming/SKILL.md +166 -0
  17. package/skills/cometchat-android-v5-troubleshooting/SKILL.md +73 -0
  18. package/skills/cometchat-android-v6/SKILL.md +107 -0
  19. package/skills/cometchat-android-v6-builder-settings/SKILL.md +145 -0
  20. package/skills/cometchat-android-v6-compose-components/SKILL.md +202 -0
  21. package/skills/cometchat-android-v6-compose-customization/SKILL.md +280 -0
  22. package/skills/cometchat-android-v6-compose-placement/SKILL.md +213 -0
  23. package/skills/cometchat-android-v6-compose-theming/SKILL.md +224 -0
  24. package/skills/cometchat-android-v6-core/SKILL.md +354 -0
  25. package/skills/cometchat-android-v6-events/SKILL.md +212 -0
  26. package/skills/cometchat-android-v6-extensions/SKILL.md +191 -0
  27. package/skills/cometchat-android-v6-features/SKILL.md +130 -0
  28. package/skills/cometchat-android-v6-kotlin-components/SKILL.md +197 -0
  29. package/skills/cometchat-android-v6-kotlin-customization/SKILL.md +268 -0
  30. package/skills/cometchat-android-v6-kotlin-placement/SKILL.md +248 -0
  31. package/skills/cometchat-android-v6-kotlin-theming/SKILL.md +202 -0
  32. package/skills/cometchat-android-v6-production/SKILL.md +187 -0
  33. package/skills/cometchat-android-v6-push/SKILL.md +274 -0
  34. package/skills/cometchat-android-v6-testing/SKILL.md +279 -0
  35. package/skills/cometchat-android-v6-troubleshooting/SKILL.md +249 -0
  36. package/skills/cometchat-angular-components/SKILL.md +706 -0
  37. package/skills/cometchat-angular-core/SKILL.md +444 -0
  38. package/skills/cometchat-angular-customization/SKILL.md +424 -0
  39. package/skills/cometchat-angular-features/SKILL.md +447 -0
  40. package/skills/cometchat-angular-patterns/SKILL.md +447 -0
  41. package/skills/cometchat-angular-placement/SKILL.md +685 -0
  42. package/skills/cometchat-angular-production/SKILL.md +415 -0
  43. package/skills/cometchat-angular-theming/SKILL.md +365 -0
  44. package/skills/cometchat-angular-troubleshooting/SKILL.md +329 -0
  45. package/skills/cometchat-astro-patterns/SKILL.md +3 -3
  46. package/skills/cometchat-components/SKILL.md +11 -0
  47. package/skills/cometchat-core/SKILL.md +11 -6
  48. package/skills/cometchat-customization/references/component-catalog.md +1 -1
  49. package/skills/cometchat-features/SKILL.md +176 -108
  50. package/skills/cometchat-flutter-v5/SKILL.md +167 -0
  51. package/skills/cometchat-flutter-v5-calls/SKILL.md +192 -0
  52. package/skills/cometchat-flutter-v5-conversations/SKILL.md +117 -0
  53. package/skills/cometchat-flutter-v5-core/SKILL.md +221 -0
  54. package/skills/cometchat-flutter-v5-customization/SKILL.md +227 -0
  55. package/skills/cometchat-flutter-v5-events/SKILL.md +155 -0
  56. package/skills/cometchat-flutter-v5-messages/SKILL.md +258 -0
  57. package/skills/cometchat-flutter-v5-production/SKILL.md +207 -0
  58. package/skills/cometchat-flutter-v5-push/SKILL.md +284 -0
  59. package/skills/cometchat-flutter-v5-theming/SKILL.md +160 -0
  60. package/skills/cometchat-flutter-v5-troubleshooting/SKILL.md +129 -0
  61. package/skills/cometchat-flutter-v5-users-groups/SKILL.md +151 -0
  62. package/skills/cometchat-flutter-v6/SKILL.md +445 -0
  63. package/skills/cometchat-flutter-v6-calls/SKILL.md +333 -0
  64. package/skills/cometchat-flutter-v6-components/SKILL.md +365 -0
  65. package/skills/cometchat-flutter-v6-conversations/SKILL.md +210 -0
  66. package/skills/cometchat-flutter-v6-core/SKILL.md +305 -0
  67. package/skills/cometchat-flutter-v6-customization/SKILL.md +666 -0
  68. package/skills/cometchat-flutter-v6-events/SKILL.md +216 -0
  69. package/skills/cometchat-flutter-v6-features/SKILL.md +406 -0
  70. package/skills/cometchat-flutter-v6-messages/SKILL.md +333 -0
  71. package/skills/cometchat-flutter-v6-migration/SKILL.md +381 -0
  72. package/skills/cometchat-flutter-v6-placement/SKILL.md +398 -0
  73. package/skills/cometchat-flutter-v6-production/SKILL.md +632 -0
  74. package/skills/cometchat-flutter-v6-theming/SKILL.md +260 -0
  75. package/skills/cometchat-flutter-v6-troubleshooting/SKILL.md +726 -0
  76. package/skills/cometchat-flutter-v6-users-groups/SKILL.md +216 -0
  77. package/skills/cometchat-ios/SKILL.md +323 -0
  78. package/skills/cometchat-ios-components/SKILL.md +651 -0
  79. package/skills/cometchat-ios-core/SKILL.md +822 -0
  80. package/skills/cometchat-ios-customization/SKILL.md +825 -0
  81. package/skills/cometchat-ios-features/SKILL.md +725 -0
  82. package/skills/cometchat-ios-placement/SKILL.md +750 -0
  83. package/skills/cometchat-ios-production/SKILL.md +730 -0
  84. package/skills/cometchat-ios-push/SKILL.md +582 -0
  85. package/skills/cometchat-ios-theming/SKILL.md +631 -0
  86. package/skills/cometchat-ios-troubleshooting/SKILL.md +983 -0
  87. package/skills/cometchat-native-bare-patterns/SKILL.md +470 -0
  88. package/skills/cometchat-native-components/SKILL.md +594 -0
  89. package/skills/cometchat-native-core/SKILL.md +407 -0
  90. package/skills/cometchat-native-customization/SKILL.md +594 -0
  91. package/skills/cometchat-native-expo-patterns/SKILL.md +485 -0
  92. package/skills/cometchat-native-features/SKILL.md +608 -0
  93. package/skills/cometchat-native-placement/SKILL.md +500 -0
  94. package/skills/cometchat-native-production/SKILL.md +694 -0
  95. package/skills/cometchat-native-push/SKILL.md +593 -0
  96. package/skills/cometchat-native-testing/SKILL.md +583 -0
  97. package/skills/cometchat-native-theming/SKILL.md +656 -0
  98. package/skills/cometchat-native-troubleshooting/SKILL.md +433 -0
  99. package/skills/cometchat-nextjs-patterns/SKILL.md +5 -5
  100. package/skills/cometchat-production/SKILL.md +60 -0
  101. package/skills/cometchat-react-router-patterns/SKILL.md +23 -21
@@ -0,0 +1,583 @@
1
+ ---
2
+ name: cometchat-native-testing
3
+ 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."
4
+ license: "MIT"
5
+ compatibility: "Node.js >=18; React Native >=0.70; @cometchat/chat-uikit-react-native ^5; Jest ^29; @testing-library/react-native ^12"
6
+ allowed-tools: "executeBash, readFile, fileSearch, listDirectory"
7
+ metadata:
8
+ author: "CometChat"
9
+ version: "3.0.0"
10
+ tags: "cometchat react-native testing jest rnt detox maestro ci"
11
+ ---
12
+
13
+ ## Purpose
14
+
15
+ Teaches Claude how to write and run tests against a CometChat React Native integration. Covers:
16
+
17
+ - Unit / component tests with Jest + React Native Testing Library (RNTL)
18
+ - How to mock `@cometchat/chat-uikit-react-native` and `@cometchat/chat-sdk-react-native` (both pull in native modules that fail in Node's jest-expo / jest-react-native environments)
19
+ - Testing custom bubbles, headers, composer actions, empty states
20
+ - Snapshot testing pitfalls specific to theme-driven components
21
+ - E2E with Detox (iOS + Android native drivers) vs Maestro (declarative YAML)
22
+ - Which tests catch real regressions vs which are flaky churn
23
+
24
+ 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).
25
+
26
+ ---
27
+
28
+ ## 1. What to test, what to skip
29
+
30
+ Not every test is worth the maintenance cost. A few rules of thumb:
31
+
32
+ **Worth testing:**
33
+ - Custom components you wrote (custom bubble, custom header, empty-state view)
34
+ - Navigation logic triggered by CometChat events (push tap → deep-link)
35
+ - Message render logic with text formatters
36
+ - Your provider chain wires correctly (four-wrapper order, init called, login called)
37
+ - Production auth token refresh + retry logic
38
+ - User-ID mapping (Firebase UID → CometChat UID)
39
+
40
+ **Skip:**
41
+ - UI Kit internals — that's the UI Kit's responsibility. Testing `<CometChatConversations>` renders a list is testing CometChat's code.
42
+ - Realtime delivery (A sends, B receives) — requires real servers; flaky and slow; use manual QA or E2E with real accounts.
43
+ - Presence / typing indicators — race-prone, depend on socket state.
44
+ - Snapshot tests of CometChat components — theme changes, UI Kit updates, and `cometchat-native-theming` edits all churn the snapshots with no real signal.
45
+ - Native module calls (camera, picker) — Jest's mocks already return stubs; testing them verifies the mock, not the integration.
46
+
47
+ 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.
48
+
49
+ ---
50
+
51
+ ## 2. Toolchain
52
+
53
+ | Layer | Tool | Why |
54
+ |---|---|---|
55
+ | Unit + component tests | Jest + `@testing-library/react-native` | The RN default. Preset handles metro module resolution. |
56
+ | Mocking | Jest `moduleNameMapper` + manual mocks | UI Kit imports native modules — can't run real components in a Node env. |
57
+ | Snapshot | Jest's built-in | Use sparingly — see §7 |
58
+ | E2E | Maestro OR Detox | See §10 for tradeoff |
59
+ | CI | GitHub Actions / EAS / Bitrise | §11 |
60
+
61
+ Install:
62
+ ```bash
63
+ # Bare RN
64
+ npm install --save-dev jest @testing-library/react-native @testing-library/jest-native \
65
+ react-test-renderer @types/jest
66
+
67
+ # Expo
68
+ npx expo install --dev jest-expo @testing-library/react-native @testing-library/jest-native \
69
+ react-test-renderer
70
+ ```
71
+
72
+ `jest-expo` wraps `react-native` preset with Expo-specific module resolution (handles `expo-modules-core`, `expo-router`, etc.).
73
+
74
+ ---
75
+
76
+ ## 3. Jest config
77
+
78
+ **Bare RN** — `jest.config.js`:
79
+ ```js
80
+ module.exports = {
81
+ preset: "react-native",
82
+ setupFilesAfterEach: ["<rootDir>/jest.setup.ts"],
83
+ transformIgnorePatterns: [
84
+ "node_modules/(?!(?:react-native|@react-native|@react-navigation|" +
85
+ "@cometchat/chat-uikit-react-native|@cometchat/chat-sdk-react-native|" +
86
+ "react-native-.+|@notifee/react-native)/)",
87
+ ],
88
+ moduleNameMapper: {
89
+ "^@cometchat/chat-uikit-react-native$": "<rootDir>/__mocks__/cometchat-uikit.ts",
90
+ "^@cometchat/chat-sdk-react-native$": "<rootDir>/__mocks__/cometchat-sdk.ts",
91
+ },
92
+ };
93
+ ```
94
+
95
+ **Expo** — `jest.config.js`:
96
+ ```js
97
+ module.exports = {
98
+ preset: "jest-expo",
99
+ setupFilesAfterEach: ["<rootDir>/jest.setup.ts"],
100
+ transformIgnorePatterns: [
101
+ "node_modules/(?!(?:(jest-)?react-native|@react-native|expo(nent)?|@expo(nent)?/.*|" +
102
+ "@expo-google-fonts/.*|react-navigation|@react-navigation/.*|" +
103
+ "@cometchat/chat-uikit-react-native|@cometchat/chat-sdk-react-native|" +
104
+ "@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)/)",
105
+ ],
106
+ moduleNameMapper: {
107
+ "^@cometchat/chat-uikit-react-native$": "<rootDir>/__mocks__/cometchat-uikit.ts",
108
+ "^@cometchat/chat-sdk-react-native$": "<rootDir>/__mocks__/cometchat-sdk.ts",
109
+ },
110
+ };
111
+ ```
112
+
113
+ **`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.
114
+
115
+ ---
116
+
117
+ ## 4. Global setup — `jest.setup.ts`
118
+
119
+ ```ts
120
+ import "@testing-library/jest-native/extend-expect";
121
+
122
+ // Silence RN's "AnimatedValue" warning noise in tests
123
+ jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper");
124
+
125
+ // Mock native modules that the UI Kit pulls in
126
+ jest.mock("react-native-gesture-handler", () => {
127
+ const View = require("react-native/Libraries/Components/View/View");
128
+ return {
129
+ GestureHandlerRootView: View,
130
+ PanGestureHandler: View,
131
+ TapGestureHandler: View,
132
+ State: {},
133
+ Directions: {},
134
+ };
135
+ });
136
+
137
+ // react-native-reanimated is NOT a peer dep of the kit. Only add this
138
+ // mock if your app installs reanimated for its own animation needs.
139
+ // jest.mock("react-native-reanimated", () =>
140
+ // require("react-native-reanimated/mock"),
141
+ // );
142
+
143
+ jest.mock("react-native-safe-area-context", () => ({
144
+ SafeAreaProvider: ({ children }: { children: React.ReactNode }) => children,
145
+ SafeAreaView: ({ children }: { children: React.ReactNode }) => children,
146
+ useSafeAreaInsets: () => ({ top: 0, right: 0, bottom: 0, left: 0 }),
147
+ }));
148
+
149
+ // Silence console.warn from legacy components in tests — re-enable locally if debugging
150
+ const originalWarn = console.warn;
151
+ console.warn = (...args: unknown[]) => {
152
+ if (
153
+ typeof args[0] === "string" &&
154
+ /componentWill|Unable to find|act\(\)/i.test(args[0])
155
+ ) {
156
+ return;
157
+ }
158
+ originalWarn(...args);
159
+ };
160
+ ```
161
+
162
+ ---
163
+
164
+ ## 5. Mocking the UI Kit
165
+
166
+ The UI Kit's top-level components (`CometChatConversations`, `CometChatMessageList`, etc.) wire socket listeners, call native modules, and render FlatLists with async data. Rendering them in Jest is more effort than value.
167
+
168
+ **Strategy: mock them as transparent Views that forward children.** This lets your tests verify your integration (are the right props being passed? does the right component mount in the right screen?) without pulling in the real implementation.
169
+
170
+ `__mocks__/cometchat-uikit.ts`:
171
+ ```ts
172
+ import React from "react";
173
+ import { View } from "react-native";
174
+
175
+ const passThrough = (name: string) =>
176
+ React.forwardRef<unknown, Record<string, unknown>>((props, ref) => {
177
+ const { children, ...rest } = props as { children?: React.ReactNode };
178
+ return (
179
+ <View ref={ref as never} testID={name} {...rest}>
180
+ {children}
181
+ </View>
182
+ );
183
+ });
184
+
185
+ export const CometChatUIKit = {
186
+ init: jest.fn(async () => undefined),
187
+ login: jest.fn(async () => ({ getUid: () => "cometchat-uid-1" })),
188
+ logout: jest.fn(async () => undefined),
189
+ getLoggedInUser: jest.fn(async () => ({ getUid: () => "cometchat-uid-1" })),
190
+ };
191
+
192
+ // NOTE: the v5 RN UI Kit does NOT export `UIKitSettingsBuilder` — `init()` takes
193
+ // a flat `UIKitSettings` object. No mock needed for a builder that doesn't exist.
194
+
195
+ export const CometChatThemeProvider = passThrough("CometChatThemeProvider");
196
+ export const CometChatI18nProvider = passThrough("CometChatI18nProvider");
197
+ export const CometChatConversations = passThrough("CometChatConversations");
198
+ export const CometChatMessageList = passThrough("CometChatMessageList");
199
+ export const CometChatMessageComposer = passThrough("CometChatMessageComposer");
200
+ export const CometChatMessageHeader = passThrough("CometChatMessageHeader");
201
+ export const CometChatUsers = passThrough("CometChatUsers");
202
+ export const CometChatGroups = passThrough("CometChatGroups");
203
+ export const CometChatIncomingCall = passThrough("CometChatIncomingCall");
204
+ export const CometChatOutgoingCall = passThrough("CometChatOutgoingCall");
205
+
206
+ export const CometChatUIEventHandler = {
207
+ addUIListener: jest.fn(),
208
+ removeListener: jest.fn(),
209
+ };
210
+ export const CometChatUIEvents = {};
211
+
212
+ export const useTheme = () => ({
213
+ color: {
214
+ primary: "#6852D6",
215
+ background1: "#FFFFFF",
216
+ textPrimary: "#141414",
217
+ },
218
+ typography: {
219
+ heading1: { fontFamily: "System", fontSize: 28 },
220
+ body1: { fontFamily: "System", fontSize: 16 },
221
+ },
222
+ });
223
+ ```
224
+
225
+ `__mocks__/cometchat-sdk.ts`:
226
+ ```ts
227
+ export const CometChat = {
228
+ getUser: jest.fn(async (uid: string) => ({ getUid: () => uid, getName: () => "Test User" })),
229
+ getGroup: jest.fn(async (guid: string) => ({ getGuid: () => guid, getName: () => "Test Group" })),
230
+ addMessageListener: jest.fn(),
231
+ removeMessageListener: jest.fn(),
232
+ };
233
+
234
+ export const CometChatNotifications = {
235
+ PushPlatforms: {
236
+ FCM_REACT_NATIVE_ANDROID: "fcm-android",
237
+ FCM_REACT_NATIVE_IOS: "fcm-ios",
238
+ APNS_REACT_NATIVE_DEVICE: "apns-device",
239
+ APNS_REACT_NATIVE_VOIP: "apns-voip",
240
+ },
241
+ registerPushToken: jest.fn(async () => ({ success: true })),
242
+ unregisterPushToken: jest.fn(async () => ({ success: true })),
243
+ };
244
+ ```
245
+
246
+ Every real `<CometChatMessageList>` in your code renders as `<View testID="CometChatMessageList">` in tests. You can assert on `testID` + the props you passed.
247
+
248
+ ---
249
+
250
+ ## 6. Testing a custom component
251
+
252
+ Example — a custom chat screen that renders `<CometChatMessageList>` for a specific user:
253
+
254
+ ```tsx
255
+ // src/screens/MessagesScreen.tsx
256
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
257
+ import { CometChatMessageList } from "@cometchat/chat-uikit-react-native";
258
+ import { useEffect, useState } from "react";
259
+
260
+ export function MessagesScreen({ uid }: { uid: string }) {
261
+ const [user, setUser] = useState<CometChat.User | null>(null);
262
+
263
+ useEffect(() => {
264
+ CometChat.getUser(uid).then(setUser);
265
+ }, [uid]);
266
+
267
+ if (!user) return null;
268
+
269
+ return <CometChatMessageList user={user} hideReplyInThreadOption />;
270
+ }
271
+ ```
272
+
273
+ Test:
274
+ ```tsx
275
+ // src/screens/__tests__/MessagesScreen.test.tsx
276
+ import { render, waitFor } from "@testing-library/react-native";
277
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
278
+ import { MessagesScreen } from "../MessagesScreen";
279
+
280
+ test("fetches user then renders MessageList", async () => {
281
+ const { getByTestId, queryByTestId } = render(<MessagesScreen uid="alice" />);
282
+
283
+ // Before fetch resolves — nothing rendered
284
+ expect(queryByTestId("CometChatMessageList")).toBeNull();
285
+
286
+ // After fetch resolves — list renders with user prop
287
+ await waitFor(() => expect(getByTestId("CometChatMessageList")).toBeTruthy());
288
+
289
+ expect(CometChat.getUser).toHaveBeenCalledWith("alice");
290
+ });
291
+
292
+ test("passes hideReplyInThreadOption to MessageList", async () => {
293
+ const { findByTestId } = render(<MessagesScreen uid="alice" />);
294
+ const list = await findByTestId("CometChatMessageList");
295
+
296
+ // The mocked component stored props on the View — check them
297
+ expect(list.props.hideReplyInThreadOption).toBe(true);
298
+ });
299
+ ```
300
+
301
+ The second test is the valuable one — it guards the mandatory `hideReplyInThreadOption` flag (hard rule §4 in `cometchat-native-core`) against a future refactor dropping it.
302
+
303
+ ---
304
+
305
+ ## 7. Snapshot testing — use sparingly
306
+
307
+ **Do snapshot:**
308
+ - Pure presentational components with no UI Kit dependency
309
+ - Custom bubble renderers with fixed inputs
310
+ - Data transforms (message → display string)
311
+
312
+ **Don't snapshot:**
313
+ - Anything wrapped in `CometChatThemeProvider` — a token change churns snapshots with no regression meaning.
314
+ - Components rendering UI Kit internals — even with mocks, prop churn from UI Kit updates churns your snapshots.
315
+ - Navigators / full screens — too many variables.
316
+
317
+ ```tsx
318
+ // Good — isolated, theme-free
319
+ test("formatTimestamp(1700000000000) matches snapshot", () => {
320
+ expect(formatTimestamp(1_700_000_000_000)).toMatchInlineSnapshot(`"Tue, 14 Nov 2023"`);
321
+ });
322
+ ```
323
+
324
+ If a snapshot test churns on every UI Kit update, delete it — it's net-negative.
325
+
326
+ ---
327
+
328
+ ## 8. Testing the provider chain
329
+
330
+ The four-wrapper chain (hard rule §3 in `cometchat-native-core`) is one of the most common regressions AI edits introduce. Test that all four wrappers render:
331
+
332
+ ```tsx
333
+ // src/App.test.tsx
334
+ import { render } from "@testing-library/react-native";
335
+ import App from "./App";
336
+
337
+ test("App mounts all four CometChat wrappers", () => {
338
+ const { getByTestId } = render(<App />);
339
+
340
+ // The mocked wrappers each render a View with testID matching their name
341
+ expect(getByTestId("CometChatThemeProvider")).toBeTruthy();
342
+ // Note: GestureHandlerRootView and SafeAreaProvider are pass-through Views
343
+ // without distinct testIDs in our setup, so assert via presence of children
344
+ // OR extend the mock in jest.setup.ts to add testIDs.
345
+ });
346
+ ```
347
+
348
+ For the `GestureHandlerRootView` + `SafeAreaProvider` assertion, extend their mocks in `jest.setup.ts` to add `testID`:
349
+
350
+ ```ts
351
+ jest.mock("react-native-gesture-handler", () => {
352
+ const { View } = require("react-native");
353
+ return {
354
+ GestureHandlerRootView: (props: any) =>
355
+ require("react").createElement(View, { ...props, testID: "GestureHandlerRootView" }),
356
+ // ...
357
+ };
358
+ });
359
+ ```
360
+
361
+ ---
362
+
363
+ ## 9. Testing login lifecycle
364
+
365
+ The `ensureLoggedIn` helper (hard rule §2 in `cometchat-native-core`) must handle concurrent calls safely:
366
+
367
+ ```tsx
368
+ // src/providers/__tests__/CometChatProvider.test.tsx
369
+ import { CometChatUIKit } from "@cometchat/chat-uikit-react-native";
370
+ import { ensureLoggedIn } from "../CometChatProvider";
371
+
372
+ beforeEach(() => {
373
+ jest.clearAllMocks();
374
+ });
375
+
376
+ test("concurrent ensureLoggedIn calls only invoke login once", async () => {
377
+ (CometChatUIKit.getLoggedInUser as jest.Mock).mockResolvedValue(null);
378
+
379
+ const results = await Promise.all([
380
+ ensureLoggedIn("alice"),
381
+ ensureLoggedIn("alice"),
382
+ ensureLoggedIn("alice"),
383
+ ]);
384
+
385
+ expect(CometChatUIKit.login).toHaveBeenCalledTimes(1);
386
+ });
387
+
388
+ test("already-logged-in skips login entirely", async () => {
389
+ (CometChatUIKit.getLoggedInUser as jest.Mock).mockResolvedValue({
390
+ getUid: () => "alice",
391
+ });
392
+
393
+ await ensureLoggedIn("alice");
394
+
395
+ expect(CometChatUIKit.login).not.toHaveBeenCalled();
396
+ });
397
+ ```
398
+
399
+ These two tests catch the most common `ensureLoggedIn` breakages — dropping the module-level promise guard, or forgetting the `getLoggedInUser` short-circuit.
400
+
401
+ ---
402
+
403
+ ## 10. E2E — Detox vs Maestro
404
+
405
+ Two choices for end-to-end. Different philosophies.
406
+
407
+ | | Detox | Maestro |
408
+ |---|---|---|
409
+ | Config | Native drivers (iOS + Android). `.detoxrc.js`. | YAML flows. Single binary. |
410
+ | Language | JavaScript / TypeScript | YAML |
411
+ | Setup | Heavy — Xcode build, Detox CLI, Jest runner | Light — brew install, run CLI |
412
+ | CI | Slow (full native build each run) | Fast (reuses install) |
413
+ | Speed | Flaky in CI, reliable locally | Fast, stable |
414
+ | iOS + Android parity | Yes | Yes |
415
+ | Cloud runs | No native cloud support | Maestro Cloud (paid) |
416
+ | Learning curve | Steep if you don't know RN internals | Low |
417
+
418
+ **Recommendation: Maestro for most teams.** Flows are readable, runs in seconds, CI-friendly. Detox makes sense if you have existing Jest infrastructure and want E2E to live in the same runner.
419
+
420
+ ### Maestro flow (recommended)
421
+
422
+ `.maestro/chat-happy-path.yaml`:
423
+ ```yaml
424
+ appId: com.yourapp.mobile
425
+ ---
426
+ - launchApp
427
+ - tapOn: "Login"
428
+ - inputText: "cometchat-uid-1"
429
+ - tapOn: "Continue"
430
+ - assertVisible: "Messages"
431
+ - tapOn: "Messages"
432
+ - assertVisible: "Conversations"
433
+ - tapOn: id: "conversation-cometchat-uid-2"
434
+ - inputText: "Hello from Maestro"
435
+ - tapOn: id: "send-button"
436
+ - assertVisible: "Hello from Maestro"
437
+ ```
438
+
439
+ Run:
440
+ ```bash
441
+ maestro test .maestro/chat-happy-path.yaml
442
+ ```
443
+
444
+ Needs your RN `<CometChatMessageComposer>` to expose `testID="send-button"` — the UI Kit supports this via the `sendButtonStyle` slot or via a Custom view template.
445
+
446
+ ### Detox
447
+
448
+ `.detoxrc.js` (abbreviated):
449
+ ```js
450
+ module.exports = {
451
+ testRunner: { args: { $0: "jest", config: "e2e/jest.config.js" } },
452
+ apps: {
453
+ "ios.debug": {
454
+ type: "ios.app",
455
+ binaryPath: "ios/build/Build/Products/Debug-iphonesimulator/YourApp.app",
456
+ },
457
+ },
458
+ devices: { simulator: { type: "ios.simulator", device: { type: "iPhone 15" } } },
459
+ configurations: {
460
+ "ios.sim.debug": { device: "simulator", app: "ios.debug" },
461
+ },
462
+ };
463
+ ```
464
+
465
+ Test:
466
+ ```ts
467
+ // e2e/chat.test.ts
468
+ describe("chat flow", () => {
469
+ beforeAll(async () => {
470
+ await device.launchApp();
471
+ });
472
+
473
+ it("sends a message", async () => {
474
+ await element(by.text("Login")).tap();
475
+ await element(by.id("uid-input")).typeText("cometchat-uid-1");
476
+ await element(by.text("Continue")).tap();
477
+ await element(by.text("Messages")).tap();
478
+ await element(by.id("conversation-cometchat-uid-2")).tap();
479
+ await element(by.id("message-input")).typeText("Hello from Detox");
480
+ await element(by.id("send-button")).tap();
481
+ await expect(element(by.text("Hello from Detox"))).toBeVisible();
482
+ });
483
+ });
484
+ ```
485
+
486
+ Detox needs a native dev build first (`detox build --configuration ios.sim.debug`) — slow in CI.
487
+
488
+ ### What NOT to E2E
489
+
490
+ - Login with a real auth provider (Firebase / Clerk). Mock the auth callback or use a test account with a fixed password.
491
+ - Real push delivery. Fire via a CI-only fake push tool, or skip entirely.
492
+ - Group calls with real peers. Use two simulators only if Detox/Maestro supports it (both do, but flaky).
493
+
494
+ ---
495
+
496
+ ## 11. CI integration
497
+
498
+ ### GitHub Actions — Jest on every push
499
+
500
+ `.github/workflows/test.yml`:
501
+ ```yaml
502
+ name: test
503
+ on: [push, pull_request]
504
+ jobs:
505
+ jest:
506
+ runs-on: ubuntu-latest
507
+ steps:
508
+ - uses: actions/checkout@v4
509
+ - uses: actions/setup-node@v4
510
+ with:
511
+ node-version: 20
512
+ cache: npm
513
+ - run: npm ci
514
+ - run: npx tsc --noEmit
515
+ - run: npm test -- --ci --coverage
516
+ ```
517
+
518
+ ### Maestro in CI
519
+
520
+ Maestro runs on macOS runners (iOS) or Linux runners with Android emulators. The `mobile-dev-inc/action-maestro-cloud` action simplifies it:
521
+
522
+ ```yaml
523
+ e2e:
524
+ runs-on: macos-14
525
+ steps:
526
+ - uses: actions/checkout@v4
527
+ - name: Build iOS
528
+ run: |
529
+ cd ios
530
+ pod install
531
+ xcodebuild -workspace YourApp.xcworkspace -scheme YourApp \
532
+ -sdk iphonesimulator -configuration Debug \
533
+ -derivedDataPath build
534
+ - name: Run Maestro flows
535
+ uses: mobile-dev-inc/action-maestro-cloud@v1
536
+ with:
537
+ api-key: ${{ secrets.MAESTRO_CLOUD_API_KEY }}
538
+ app-file: ios/build/Build/Products/Debug-iphonesimulator/YourApp.app
539
+ workspace: .maestro
540
+ ```
541
+
542
+ ### EAS + Expo
543
+
544
+ If you're on EAS, `eas build --profile preview` followed by `maestro test` against the preview build works for CI smoke tests. EAS Test (paid) orchestrates Maestro runs across multiple devices.
545
+
546
+ ---
547
+
548
+ ## 12. Common failure modes
549
+
550
+ | Symptom | Cause | Fix |
551
+ |---|---|---|
552
+ | `SyntaxError: Unexpected token 'export'` | Jest not transforming a UI Kit or SDK file | Add package name to `transformIgnorePatterns` allow list |
553
+ | `TypeError: Cannot read properties of undefined (reading 'Directions')` | Gesture handler native module missing | Mock in `jest.setup.ts` (see §4) |
554
+ | Tests hang for 30s+ | Real WebSocket or fetch not mocked | Add `jest.useFakeTimers()` + mock `fetch` |
555
+ | Snapshot fails after no code change | Theme token update churned output | Either delete the snapshot (§7) or run `--updateSnapshot` |
556
+ | `useInsertionEffect must not schedule updates` warning | React Navigation dev warning, harmless in tests | Silence in `jest.setup.ts` (see §4) |
557
+ | `Could not find React Testing Library matchers` | `@testing-library/jest-native` not extended | `import "@testing-library/jest-native/extend-expect"` in setup |
558
+ | Maestro "app not installed" | Bundle ID mismatch or simulator not booted | `xcrun simctl boot "iPhone 15"`, verify `appId` in YAML |
559
+ | Detox "Cannot find element" | `testID` not set on UI Kit component | Add via slot view template or custom view; don't rely on text matching |
560
+
561
+ ---
562
+
563
+ ## 13. Hard rules
564
+
565
+ - **Mock the UI Kit and SDK in every test file.** Running real components in Node fails on native modules and wastes CI time even when it works.
566
+ - **Don't test what the UI Kit already tests.** You're responsible for YOUR code — bubbles, headers, navigation, auth mapping. UI Kit internals are CometChat's job.
567
+ - **Skip realtime and presence.** They require real servers and produce flaky suites. Use manual QA or E2E with real test accounts.
568
+ - **Assert on `testID` and prop values, not on pixel output.** Theme changes, font metrics, and platform differences all churn pixel-level assertions.
569
+ - **Keep snapshot tests scoped.** Use for pure data transforms and isolated presentational code. Never snapshot a full screen.
570
+ - **E2E tests run against a dev build, not Jest.** Don't try to test real CometChat flow in Jest — it belongs in Detox/Maestro.
571
+
572
+ ---
573
+
574
+ ## 14. Skill routing
575
+
576
+ | This skill | Covers |
577
+ |---|---|
578
+ | `cometchat-native-testing` (this) | Jest + RNTL setup, mocking UI Kit + SDK, component / provider / login tests, Detox vs Maestro for E2E, CI |
579
+ | `cometchat-native-core` | The provider chain + login concurrency patterns you're testing |
580
+ | `cometchat-native-components` | Component catalog — what props to assert in tests |
581
+ | `cometchat-native-customization` | DataSource decorators + custom views — test per §6 |
582
+ | `cometchat-native-push` | Push tests (mock `CometChatNotifications`); E2E tap-to-deep-link needs a real device |
583
+ | `cometchat-native-troubleshooting` | Metro cache / pod install / native module errors (often surface first in a CI run) |