cometchat-react-native-testing

v2026.09.25

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.

GitHub
安装命令
npx skhub add cometchat/cometchat-react-native-testing
Markdown
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

FlowWhy it cannot be a unit test
composer survives the keyboardneeds a real soft keyboard
hardware back navigatesneeds the OS back gesture
gestures respondproves GestureHandlerRootView is wired
release-build startupcatches 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

  1. Unmocked native peers — confusing NativeModule errors.
  2. Asserting kit internals — breaks on minor upgrades.
  3. Real credentials in tests — network flakes and leaked keys.
  4. Claiming push/calls coverage from a simulator run.
  5. 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-v5 is green.
发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.25

发布时间

Sep 25, 2026

分类

未分类

许可证

MIT

源路径

skills/cometchat-react-native-testing

默认分支

main

最新提交

f92ff9e

Tree SHA

f40470f