cometchat-react-native-testing
Test a CometChat React Native integration — mock the SDK for Jest unit tests, assert init-before-render ordering and no-Auth-Key-in-source, and use Detox for the flows only a device can prove. Triggers: test CometChat React Native, mock CometChat SDK jest, detox CometChat, unit test chat screen RN, CI tests for chat.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 1.6k
- Forks
- 491
01 前言 Front Matter
- name
- cometchat-react-native-testing
- license
- MIT
- metadata
- { "tags": "chat cometchat react-native testing jest detox mocking ci", "author": "CometChat", "version": "1.0.0" }
- description
- Test a CometChat React Native integration — mock the SDK for Jest unit tests, assert init-before-render ordering and no-Auth-Key-in-source, and use Detox for the flows only a device can prove. Triggers: test CometChat React Native, mock CometChat SDK jest, detox CometChat, unit test chat screen RN, CI tests for chat.
- compatibility
- React Native >=0.77; Jest; @testing-library/react-native; Detox (e2e)
03 SKILL.md 正文
Ground truth:
catalogs/rn-v5.json+catalogs/rn-sdk-v4.json. Build the feature; do NOT test it unless asked. Use this skill only when the developer asks for tests. Never add a test framework, e2e suite or CI to a project that did not request one.
Companion skills (read first)
cometchat-react-native-core— install, provider chain, init→login→render. Assumed, not repeated here.
Use this skill when
- "write tests for the chat screen" · "mock CometChat in Jest" · "add Detox coverage for chat"
Prerequisites & install
React Native ships Jest. Add the renderer:
npm install --save-dev @testing-library/react-native
Mock the SDK — never let a unit test hit the network
CometChat opens a websocket and needs real credentials. Mock at the module boundary:
jest.mock("@cometchat/chat-sdk-react-native", () => ({
CometChat: {
init: jest.fn().mockResolvedValue(true),
login: jest.fn().mockResolvedValue({ getUid: () => "test-uid" }),
logout: jest.fn().mockResolvedValue(true),
AppSettings: { SUBSCRIPTION_TYPE_ALL_USERS: "ALL_USERS" },
},
}));
The UI Kit also pulls native modules, so mock the peers your test path touches —
react-native-gesture-handler, react-native-svg, react-native-video,
@react-native-async-storage/async-storage. Without them the failure is a NativeModule error that
never mentions CometChat: the same confusing shape as a missing install.
What is worth asserting
Ordering — the invariant most likely to regress: init resolves before login, and no chat
component renders until login resolves.
No Auth Key in source — a cheap grep test that stops a shipped secret ever landing:
it("has no auth key in source", () => {
const src = require("fs").readFileSync("src/config.ts", "utf8");
expect(src).not.toMatch(/authKey\s*:\s*["'][A-Za-z0-9]{20,}/);
});
Wiring, not rendering — that onItemPress navigates, that onBack returns, that an opened
surface can be closed. Unwired affordances are the defect class worth catching.
Do not assert on kit internals — bubble markup, class names, child order. Those change between minors, so the test breaks with nothing actually wrong.
Detox for what only a device proves
| Flow | Why it cannot be a unit test |
|---|---|
| composer survives the keyboard | needs a real soft keyboard |
| hardware back navigates | needs the OS back gesture |
| gestures respond | proves GestureHandlerRootView is wired |
| release-build startup | catches the gesture-handler import-order crash |
Calls and push are outside Detox too — they need real hardware, real permissions and a second device. Record them as manual device checks rather than pretending they are automated.
CI
Jest with mocks runs anywhere. Detox needs a simulator — heavier, but feasible. Neither can verify calls or push, so a green CI run is not evidence that either works.
Common pitfalls
- Unmocked native peers — confusing NativeModule errors.
- Asserting kit internals — breaks on minor upgrades.
- Real credentials in tests — network flakes and leaked keys.
- Claiming push/calls coverage from a simulator run.
- Adding tests nobody asked for.
Verify it works
- Tests pass with no network access.
- No real credentials anywhere in the test tree.
npm run verify:fences:rn-v5is green.
04 同仓库更多 Skills
worktable-review-with-annotations
Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.
worktable-find-and-synthesize-context
Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.
worktable-create-or-update-docs
Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.
worktable-create-or-manage-records
Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.
worktable-create-or-manage-interactive-html
Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.
worktable-collaborate-threads
Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.