agentleFS
SentryKnown publishergetsentry/sentry-react-native/.agents/skills/test-guidelines/SKILL.md

test-guidelines

Skill1.8k starsChanged 3 months agoMITView on GitHub

Enforce Sentry React Native SDK test conventions for naming, structure, mocking, and fixtures with Jest. Use when writing tests, adding tests, modifying tests, reviewing test code, fixing failing tests, adding coverage, TDD, test-first / red-green, reproducing bugs with tests, regression tests, or test refactoring in `packages/core`.

1 other project uses a version of this.

Trending

Quiet this year.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the getsentry/sentry-react-native repository that our weekly crawl found: only 9 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Most recently taken up by

Who's talking about getsentry/sentry-react-native

The biggest 5 of 9 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 9

Talked about on GitHub (9 times).

On GitHub · 9

4 more on GitHub

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 4 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Follow the convention in packages/core/AGENTS.md: describe/it blocks (preferred), with the it describing the expected behavior for a given …

    line 26
  2. Very specific:

    Write it as a clear behavior description, e.g.

    line 30
  3. Distinctive:

    Use specific matchers — they produce better failure messages:

    line 61
  4. Very specific:

    Reset between tests: Use afterEach(() => { jest.clearAllMocks().

    line 75
  5. Very specific:

    Mock the native module, not the whole SDK: Prefer the shared helpers (test/mockWrapper.ts, test/mocks/) over re-mocking react-native ad hoc.

    line 76
  6. Very specific:

    Test both architectures / platforms: when the code branches on them.

    line 85
  7. Very specific:

    Prefer injecting a fake at a seam over jest.mock of a deep import — a test that mocks internals breaks on refactors even when behavior is …

    line 86
  8. Distinctive:

    Don't mock the thing under test.

    line 87
  9. Very specific:

    Always await async assertions.

    line 91
  10. Distinctive:

    No real network or filesystem.

    line 93
  11. Distinctive:

    Every bug fix carries a regression test that goes red before the fix and green after.

    line 99

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Apply these conventions to all new and modified tests in packages/core. Existing tests may not follow them — do not refactor them unless asked. Tests run on Jest (yarn test, yarn test:watch, yarn test:sdk, yarn test:tools).

Tests are easiest to write against code designed to accept its dependencies — when implementing the code under test, load design-first (where the seams go) and code-guidelines (the rules).

Test-first loop

Work in vertical slices. One failing test → the minimal code that makes it pass → repeat. Each test proves one thin path end-to-end, and what it teaches shapes the next.

Do not write all the tests first and then all the implementation. That horizontal slicing produces tests of imagined behavior — they assert the shape you guessed at and pass when the real behavior breaks. Write one test at a time, against behavior you can already reason about.

Fixing a bug? Reproduce it with a failing test first — see diagnosing-bugs.

File structure

  • One test file per source file. Mirror the path: src/js/client.ts → test/client.test.ts; src/js/integrations/release.ts → test/integrations/release.test.ts.
  • React component tests use .test.tsx and @testing-library/react-native.
  • A single top-level describe naming the unit under test, with nested describe/it inside it.

Naming

Follow the convention in packages/core/AGENTS.md: describe/it blocks (preferred), with the it describing the expected behavior for a given input.

  • The top-level describe names the unit under test — the exported name (myFeatureIntegration, NATIVE, the class).
  • Nested describe groups a method or a scenario; it states the behavior being verified.
  • Write it as a clear behavior description, e.g. returns expected value when input is valid.
describe('nativeLinkedErrorsIntegration', () => {
  describe('when the native module is unavailable', () => {
    it('returns the event unchanged', () => { /* ... */ });
  });

  describe('processEvent', () => {
    it('appends linked errors up to the configured limit', () => { /* ... */ });
  });
});

Style — Arrange / Act / Assert

Structure every test in three clear sections; a blank line between them is enough.

it('returns expected value when input is valid', () => {
  // Arrange
  const input = 'test';

  // Act
  const result = functionName(input);

  // Assert
  expect(result).toBe('expected');
});

Use specific matchers — they produce better failure messages:

expect(array).toHaveLength(3);          // not expect(array.length).toBe(3)
expect(obj).toMatchObject({ a: 1 });    // partial structural match
expect(fn).toThrow(Error);
await expect(promise).resolves.toBe('ok');
await expect(promise).rejects.toThrow();

Assert the exact symptom, not "didn't crash". A test that only checks a call didn't throw catches almost nothing.

Mocking

  • Reset between tests. Use afterEach(() => { jest.clearAllMocks(); }) (or resetAllMocks when you also stub implementations). A leaked mock is the most common flaky-test cause here.
  • Mock the native module, not the whole SDK. Prefer the shared helpers (test/mockWrapper.ts, test/mocks/) over re-mocking react-native ad hoc. When you must, mock the bridge surface only:
jest.mock('react-native', () => ({
  NativeModules: { RNSentry: { fetchNativeSdkInfo: jest.fn(() => Promise.resolve({})) } },
  Platform: { OS: 'ios', select: (o: any) => o.ios ?? o.default },
}));
  • Test both architectures / platforms when the code branches on them. Drive Platform.OS, isTurboModuleEnabled(), isFabricEnabled() from the test rather than assuming one.
  • Prefer injecting a fake at a seam over jest.mock of a deep import — a test that mocks internals breaks on refactors even when behavior is unchanged (see design-first: the interface is the test surface).
  • Don't mock the thing under test. Don't assert on private internals; assert on observable output (the event, the envelope, the resolved value).

Async & timers

  • Always await async assertions; return or await the promise so Jest sees failures.
  • For timing-dependent code (flush timers, debounces, retries) use fake timers (jest.useFakeTimers() + jest.advanceTimersByTime(...)), not real setTimeout — real delays make tests slow and flaky. Restore with jest.useRealTimers() in afterEach.
  • No real network or filesystem. Stub the transport / bridge.

What to test

  • The behavior at the seam a caller depends on — inputs → observable outputs.
  • Edge cases the code guidelines call out: native module missing, enableNative false, PII gating on/off, serialization round-trips across the bridge, both architectures.
  • Every bug fix carries a regression test that goes red before the fix and green after.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.