[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6C2DESFJR14Z3G38F4KZCSG":3,"skill-same:01M6C2DESFJR14Z3G38F4KZCSG":70},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":28,"linkOnly":29,"markdownContent":30,"markdownBody":31,"frontMatter":32,"refName":37,"commitSha":38,"skillDirectory":39,"forksCount":40,"repositoryHtmlUrl":41,"repositoryHomepageUrl":42,"ownerHtmlUrl":43,"ownerBlogUrl":6,"ownerDescription":44,"updatedAt":45,"install":46,"resources":59},"01M6C2DESFJR14Z3G38F4KZCSG","express-mocks-testing",null,"Unit testing pattern for Express 5 controllers using node-mocks-http and @prisma\u002Fclient mocks. Trigger: When writing unit tests for backend controllers, testing Express routes, or avoiding Supertest\u002FServer instantiation.","davidleonmayor\u002Fproyecto-grado-unimayor","davidleonmayor","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F142275316?v=4","01M6C2D07NAZV2VQE96MD4HWYW","David León","01M6C2D0BN278C193FYXQB3TME",3,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fdavidleonmayor\u002Fproyecto-grado-unimayor\u002Fblob\u002Fmain\u002Fskills\u002Fexpress-mocks-testing\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27],"testing","express mocks testing","writing","unit tests","http","server","programming","node","backend","2026-11-10 10:12:30",false,"---\nname: express-mocks-testing\ndescription: >\n  Unit testing pattern for Express 5 controllers using node-mocks-http and @prisma\u002Fclient mocks.\n  Trigger: When writing unit tests for backend controllers, testing Express routes, or avoiding Supertest\u002FServer instantiation.\nlicense: Apache-2.0\nmetadata:\n  author: gentleman-programming\n  version: \"1.0\"\n---\n\n## When to Use\n\n- When unit testing Express 5 controllers in isolation without starting the server.\n- When you want to completely decouple from a real database.\n- When testing specific logic, role filters, or validation branches inside a controller.\n- **Do NOT use this for** End-to-End (E2E) integration tests that genuinely require testing the full middleware chain (CORS, body-parser, global error handlers). For E2E, use Supertest.\n\n## Critical Patterns\n\n- **NEVER instantiate the full Server:** Do not import or instantiate `new Server()` or `app` from `server.ts`. It causes slow tests and port conflicts.\n- **Global Prisma Mock:** Always use `jest.mock(\"@prisma\u002Fclient\", () => { ... })` to intercept Prisma Client instantiations before the controller executes.\n- **Isolate Request\u002FResponse:** Use `createRequest` and `createResponse` from `node-mocks-http` to simulate Express objects.\n- **Call Controller Directly:** Invoke the controller method directly (e.g., `await controller.sendMessage(req, res)`).\n- **Clear Mocks:** Always run `jest.clearAllMocks()` in the `beforeEach` hook.\n- **Assertions:** Use `res._getJSONData()` to verify JSON responses and `res.statusCode` to check HTTP statuses.\n\n## Code Examples\n\n### Basic Controller Test Setup\n\n```typescript\nimport { createRequest, createResponse } from \"node-mocks-http\";\nimport { MyController } from \"..\u002Fmy.controller\";\nimport { PrismaClient } from \"@prisma\u002Fclient\";\n\n\u002F\u002F 1. MOCK PRISMA GLOBALLY\njest.mock(\"@prisma\u002Fclient\", () => {\n  const mPrismaClient = {\n    user: {\n      findUnique: jest.fn(),\n      create: jest.fn(),\n    },\n  };\n  return { PrismaClient: jest.fn(() => mPrismaClient) };\n});\n\nconst prismaMock = new PrismaClient() as jest.Mocked\u003Cany>;\n\ndescribe(\"MyController\", () => {\n  let controller: MyController;\n\n  beforeAll(() => {\n    controller = new MyController();\n  });\n\n  beforeEach(() => {\n    jest.clearAllMocks();\n  });\n\n  describe(\"getUser\", () => {\n    it(\"should return 200 and the user data\", async () => {\n      \u002F\u002F Arrange\n      const req = createRequest({\n        method: \"GET\",\n        url: \"\u002Fapi\u002Fusers\u002F1\",\n        params: { id: \"1\" },\n        user: { id_persona: \"admin-123\" } \u002F\u002F If testing protected routes\n      });\n      const res = createResponse();\n\n      prismaMock.user.findUnique.mockResolvedValue({ id: \"1\", name: \"John\" });\n\n      \u002F\u002F Act\n      await controller.getUser(req, res);\n\n      \u002F\u002F Assert\n      expect(res.statusCode).toBe(200);\n      expect(res._getJSONData().name).toBe(\"John\");\n      expect(prismaMock.user.findUnique).toHaveBeenCalledWith({\n        where: { id: \"1\" }\n      });\n    });\n  });\n});\n```\n\n## Commands\n\n```bash\n# Run backend tests\npnpm test\n\n# Run specific test file\npnpm jest path\u002Fto\u002Fyour\u002Fcontroller.test.ts\n```\n","## When to Use\n\n- When unit testing Express 5 controllers in isolation without starting the server.\n- When you want to completely decouple from a real database.\n- When testing specific logic, role filters, or validation branches inside a controller.\n- **Do NOT use this for** End-to-End (E2E) integration tests that genuinely require testing the full middleware chain (CORS, body-parser, global error handlers). For E2E, use Supertest.\n\n## Critical Patterns\n\n- **NEVER instantiate the full Server:** Do not import or instantiate `new Server()` or `app` from `server.ts`. It causes slow tests and port conflicts.\n- **Global Prisma Mock:** Always use `jest.mock(\"@prisma\u002Fclient\", () => { ... })` to intercept Prisma Client instantiations before the controller executes.\n- **Isolate Request\u002FResponse:** Use `createRequest` and `createResponse` from `node-mocks-http` to simulate Express objects.\n- **Call Controller Directly:** Invoke the controller method directly (e.g., `await controller.sendMessage(req, res)`).\n- **Clear Mocks:** Always run `jest.clearAllMocks()` in the `beforeEach` hook.\n- **Assertions:** Use `res._getJSONData()` to verify JSON responses and `res.statusCode` to check HTTP statuses.\n\n## Code Examples\n\n### Basic Controller Test Setup\n\n```typescript\nimport { createRequest, createResponse } from \"node-mocks-http\";\nimport { MyController } from \"..\u002Fmy.controller\";\nimport { PrismaClient } from \"@prisma\u002Fclient\";\n\n\u002F\u002F 1. MOCK PRISMA GLOBALLY\njest.mock(\"@prisma\u002Fclient\", () => {\n  const mPrismaClient = {\n    user: {\n      findUnique: jest.fn(),\n      create: jest.fn(),\n    },\n  };\n  return { PrismaClient: jest.fn(() => mPrismaClient) };\n});\n\nconst prismaMock = new PrismaClient() as jest.Mocked\u003Cany>;\n\ndescribe(\"MyController\", () => {\n  let controller: MyController;\n\n  beforeAll(() => {\n    controller = new MyController();\n  });\n\n  beforeEach(() => {\n    jest.clearAllMocks();\n  });\n\n  describe(\"getUser\", () => {\n    it(\"should return 200 and the user data\", async () => {\n      \u002F\u002F Arrange\n      const req = createRequest({\n        method: \"GET\",\n        url: \"\u002Fapi\u002Fusers\u002F1\",\n        params: { id: \"1\" },\n        user: { id_persona: \"admin-123\" } \u002F\u002F If testing protected routes\n      });\n      const res = createResponse();\n\n      prismaMock.user.findUnique.mockResolvedValue({ id: \"1\", name: \"John\" });\n\n      \u002F\u002F Act\n      await controller.getUser(req, res);\n\n      \u002F\u002F Assert\n      expect(res.statusCode).toBe(200);\n      expect(res._getJSONData().name).toBe(\"John\");\n      expect(prismaMock.user.findUnique).toHaveBeenCalledWith({\n        where: { id: \"1\" }\n      });\n    });\n  });\n});\n```\n\n## Commands\n\n```bash\n# Run backend tests\npnpm test\n\n# Run specific test file\npnpm jest path\u002Fto\u002Fyour\u002Fcontroller.test.ts\n```\n",{"name":5,"license":15,"metadata":33,"description":36},{"author":34,"version":35},"gentleman-programming","1.0","Unit testing pattern for Express 5 controllers using node-mocks-http and @prisma\u002Fclient mocks. Trigger: When writing unit tests for backend controllers, testing Express routes, or avoiding Supertest\u002FServer instantiation.\n","main","3d76dc018cdded158c4f49df5edb56829229d265","skills\u002Fexpress-mocks-testing",0,"https:\u002F\u002Fgithub.com\u002Fdavidleonmayor\u002Fproyecto-grado-unimayor","https:\u002F\u002Fproyecto-grado-unimayor-8rtknmpjt-davidleonmayors-projects.vercel.app\u002Fadmin","https:\u002F\u002Fgithub.com\u002Fdavidleonmayor","Full-stack developer focused on microservices backend","2026-11-11 00:05:51",{"source":8,"skillName":5,"commands":47,"prompt":57,"zipAvailable":58},[48,51,54],{"tool":49,"command":50},"npx","npx skills add davidleonmayor\u002Fproyecto-grado-unimayor --skill express-mocks-testing",{"tool":52,"command":53},"bunx","bunx skills add davidleonmayor\u002Fproyecto-grado-unimayor --skill express-mocks-testing",{"tool":55,"command":56},"pnpm","pnpm dlx skills add davidleonmayor\u002Fproyecto-grado-unimayor --skill express-mocks-testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fdavidleonmayor\u002Fproyecto-grado-unimayor\u002Fblob\u002Fmain\u002Fskills\u002Fexpress-mocks-testing\u002FSKILL.md",true,[60,66],{"path":61,"resourceType":62,"resourceTypeDesc":63,"sizeBytes":64,"sourceHtmlUrl":65},"templates\u002Fraw-finding.md","REFERENCE","参考文档",467,"https:\u002F\u002Fgithub.com\u002Fscullxbones\u002Farmature\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fcapturing-dogfood-findings\u002Ftemplates\u002Fraw-finding.md",{"path":67,"resourceType":62,"resourceTypeDesc":63,"sizeBytes":68,"sourceHtmlUrl":69},"templates\u002Ftheme-readme.md",172,"https:\u002F\u002Fgithub.com\u002Fscullxbones\u002Farmature\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fcapturing-dogfood-findings\u002Ftemplates\u002Ftheme-readme.md",[71,84,104,120,132,147],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":28},"01M6C2DVB157H69PFWB1XXBVZS","skill-sync","Synchronizes skill metadata to AGENTS.md Auto-invoke sections. Trigger: When syncing skill metadata to AGENTS.md.","https:\u002F\u002Fgithub.com\u002Fdavidleonmayor\u002Fproyecto-grado-unimayor\u002Fblob\u002Fmain\u002Fskills\u002Fskill-sync\u002FSKILL.md",[],[78,79,80,81,82,83],"skill sync","sync","metadata","cloud","prowler","auto",{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":28},"01M6C2DRSV8QKEFA2J94YQKWK1","skill-creator","Creates new AI agent skills following the Agent Skills spec. Trigger: When user asks to create a new skill, add agent instructions, or document patterns for AI.","https:\u002F\u002Fgithub.com\u002Fdavidleonmayor\u002Fproyecto-grado-unimayor\u002Fblob\u002Fmain\u002Fskills\u002Fskill-creator\u002FSKILL.md",[],[91,92,93,94,81,82,95,96,97,98,99,100,101,102,103],"skill creator","spec","ai agent","create","Bash","grep","read","write","edit","instructions","user","webfetch","add agent",{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":28},"01M6C2DP81DY28MKM0RKFWJQHX","skill-commit","Creates professional git commits following conventional-commits format. Trigger: When creating commits, after completing code changes, when user asks to commit.","https:\u002F\u002Fgithub.com\u002Fdavidleonmayor\u002Fproyecto-grado-unimayor\u002Fblob\u002Fmain\u002Fskills\u002Fskill-commit\u002FSKILL.md",[],[111,112,113,114,115,116,117,118,101,119,27],"skill commit","commit","frontend","git commit","code","git","commits","format","landing",{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":126,"publishedAt":28},"01M6C2DMHK8HST60TFQHMK8D94","project-info","General monorepo structure and component overview. Trigger: When AI needs project context or component locations.","https:\u002F\u002Fgithub.com\u002Fdavidleonmayor\u002Fproyecto-grado-unimayor\u002Fblob\u002Fmain\u002Fskills\u002Fproject-info\u002FSKILL.md",[],[127,128,129,130,131],"project info","component","monorepo","context","overview",{"skillNo":133,"name":134,"nameZh":6,"description":135,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":136,"categories":137,"keywords":138,"publishedAt":28},"01M6C2DHT1Q0Q87WRYBCBH3QHG","frontend-context","Frontend architecture, patterns and conventions for the Next.js 15 app. Trigger: When working on frontend code, components, pages, or API integration.","https:\u002F\u002Fgithub.com\u002Fdavidleonmayor\u002Fproyecto-grado-unimayor\u002Fblob\u002Fmain\u002Fskills\u002Ffrontend-context\u002FSKILL.md",[],[139,130,113,140,115,141,142,143,144,145,146],"frontend context","components","js","api","integration","frontend architecture","Next.js","architecture",{"skillNo":148,"name":149,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":150,"licenseFileUrl":6,"sourceHtmlUrl":151,"categories":152,"keywords":153,"publishedAt":28},"01M6C2DCXFSYWZCQWMPGWWQJQ7","backend-service","MIT","https:\u002F\u002Fgithub.com\u002Fdavidleonmayor\u002Fproyecto-grado-unimayor\u002Fblob\u002Fmain\u002Fskills\u002Fbackend-service\u002FSKILL.md",[],[154,27],"backend service"]