$npx -y skills add girijashankarj/cursor-handbook --skill fix-testsSystematic workflow for diagnosing and fixing failing tests. Use when the user reports failing tests or asks to fix test failures.
| 1 | # Skill: Fix Failing Tests |
| 2 | |
| 3 | ## Trigger |
| 4 | When the user reports failing tests or asks to fix test failures. |
| 5 | |
| 6 | ## Prerequisites |
| 7 | - [ ] Test command works: `{{CONFIG.testing.testCommand}}` |
| 8 | - [ ] Failing test file path or error output available |
| 9 | - [ ] Type check passes or run first: `{{CONFIG.testing.typeCheckCommand}}` |
| 10 | |
| 11 | ## Steps |
| 12 | |
| 13 | ### Step 1: Identify Failing Tests |
| 14 | - [ ] Run the test suite: `{{CONFIG.testing.testCommand}}` |
| 15 | - [ ] List all failing tests with error messages |
| 16 | - [ ] Categorize by failure type (assertion, timeout, mock, type) |
| 17 | |
| 18 | ### Step 2: Analyze Each Failure |
| 19 | For each failing test: |
| 20 | - [ ] Read the error message carefully |
| 21 | - [ ] Check if it's a test issue or a code issue |
| 22 | - [ ] Look at recent changes to the tested code |
| 23 | - [ ] Check if mocks are correctly set up |
| 24 | |
| 25 | ### Step 3: Common Fix Patterns |
| 26 | |
| 27 | #### Mock Issues |
| 28 | - Mock not returning expected value → Update mock return |
| 29 | - Mock not being called → Check import path |
| 30 | - Mock state leaking → Add `beforeEach` reset |
| 31 | |
| 32 | #### Assertion Issues |
| 33 | - Expected value changed → Update test or fix code |
| 34 | - Async not awaited → Add `await` or use `waitFor` |
| 35 | - Wrong matcher → Use correct Jest matcher |
| 36 | |
| 37 | #### Type Issues |
| 38 | - Interface changed → Update test data |
| 39 | - New required field → Add to test factories |
| 40 | - Return type changed → Update assertions |
| 41 | |
| 42 | ### Step 4: Fix Tests |
| 43 | - [ ] Fix one test at a time |
| 44 | - [ ] Run just that test to verify: `{{CONFIG.testing.testCommand}} -- --testPathPattern={test-file}` |
| 45 | - [ ] Ensure fix doesn't break other tests |
| 46 | |
| 47 | ### Step 5: Verify |
| 48 | - [ ] Run full affected test suite |
| 49 | - [ ] Check coverage hasn't dropped below {{CONFIG.testing.coverageMinimum}}% |
| 50 | - [ ] Run type check: `{{CONFIG.testing.typeCheckCommand}}` |
| 51 | |
| 52 | ## Completion Checklist |
| 53 | - [ ] All previously failing tests pass |
| 54 | - [ ] No new test failures introduced |
| 55 | - [ ] Coverage at or above {{CONFIG.testing.coverageMinimum}}% |
| 56 | - [ ] Type check passes |
| 57 | |
| 58 | ## If Step Fails |
| 59 | - **Step 1 (identify)**: Run `{{CONFIG.testing.testCommand}}` — if it hangs, run single file with `--testPathPattern=path/to/file` |
| 60 | - **Step 2 (analyze)**: Mock issues often from wrong import path; use `jest.mock('./path')` matching actual import |
| 61 | - **Step 4 (fix)**: Fix one test, run `--testPathPattern` to verify, then next. Don't fix all at once |
| 62 | - **Step 5 (verify)**: If coverage dropped, add test for uncovered branch. Use `@coverage-improvement` skill |
| 63 | |
| 64 | ## Example |
| 65 | Failure: "Expected 60, received undefined". Cause: mock for `calculateTotal` not returning. Fix: `mockCalculateTotal.mockReturnValue(60)` in test. Run: `npm test -- order.test.ts`. |