Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1stack specificStack: node
testingexpresssupertestintegration
Test Express endpoints through supertest rather than hand-built req/res casts
Exercise route handlers via supertest over the real app instead of casting partial objects to Request/Response, which breaks as soon as the handler touches more of req/res/next.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const mockReq = { body: {}, cookies: {} } as Request; |
| 2 | const mockRes = { status: statusMock, send: sendMock } as unknown as Response; |
| 3 | await handler(mockReq, mockRes); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | import request from 'supertest'; |
| 2 | await request(app).post('/api/forum-settings').send({ settings }).expect(401); |
Explanation (EN)
Objašnjenje (HR)