-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobile-test-coverage.mdc
More file actions
65 lines (48 loc) · 1.87 KB
/
mobile-test-coverage.mdc
File metadata and controls
65 lines (48 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
description: Flag untested components and screens, missing test files for new code, and low coverage thresholds in React Native/Expo and Flutter projects.
alwaysApply: false
globs:
- "**/*.ts"
- "**/*.tsx"
- "**/*.dart"
standards-version: 1.9.0
---
# Test Coverage
Flag these test coverage issues:
## Missing test files
- A component or screen file (`*.tsx` or `*.dart`) has no corresponding test file (`*.test.tsx`, `*.test.ts`, or `*_test.dart`) in `__tests__/` or a colocated location.
- A utility or hook file has no matching test file.
- New files added in a PR have zero test coverage.
**Fix:** Create a test file using `mobile_generateTestFile` or write tests manually. At minimum, verify the component renders and key interactions work.
## Low coverage thresholds
- Jest `coverageThreshold` in `package.json` is missing or set below 60% for statements.
- Flutter project has no coverage enforcement in CI.
**Fix (Expo):** Add to `package.json`:
```json
{
"jest": {
"coverageThreshold": {
"global": {
"statements": 60,
"branches": 50,
"functions": 60,
"lines": 60
}
}
}
}
```
**Fix (Flutter):** Add a coverage check step in CI:
```yaml
- run: flutter test --coverage
- name: Check coverage
run: |
COVERAGE=$(lcov --summary coverage/lcov.info 2>&1 | grep 'lines' | grep -o '[0-9.]*%' | head -1)
echo "Line coverage: $COVERAGE"
```
## Snapshot-only testing
- A test file contains only snapshot tests with no behavioral assertions. Snapshot-only tests provide weak coverage and break on any render change.
**Fix:** Add at least one behavioral test per component (user interaction, prop variation, or error state).
## Untested error paths
- Components with `try/catch`, error boundaries, or fallback UI have no tests for the error state.
**Fix:** Write tests that trigger the error path and verify the fallback UI renders.