[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6C2DESFJR14Z3G38F4KZCSG":3,"skill-same:01M6C2DESFJR14Z3G38F4KZCSG":78},{"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":26,"publishedAt":36,"linkOnly":37,"markdownContent":38,"markdownBody":39,"frontMatter":40,"refName":45,"commitSha":46,"skillDirectory":47,"forksCount":48,"repositoryHtmlUrl":49,"repositoryHomepageUrl":50,"ownerHtmlUrl":51,"ownerBlogUrl":6,"ownerDescription":52,"updatedAt":53,"install":54,"resources":67},"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",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000008","测试与质量","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口",[27,28,29,30,31,32,33,34,35],"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":41,"description":44},{"author":42,"version":43},"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":55,"prompt":65,"zipAvailable":66},[56,59,62],{"tool":57,"command":58},"npx","npx skills add davidleonmayor\u002Fproyecto-grado-unimayor --skill express-mocks-testing",{"tool":60,"command":61},"bunx","bunx skills add davidleonmayor\u002Fproyecto-grado-unimayor --skill express-mocks-testing",{"tool":63,"command":64},"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,[68,74],{"path":69,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":73},"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":75,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":76,"sourceHtmlUrl":77},"templates\u002Ftheme-readme.md",172,"https:\u002F\u002Fgithub.com\u002Fscullxbones\u002Farmature\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fcapturing-dogfood-findings\u002Ftemplates\u002Ftheme-readme.md",[79,95,116,136,148,169],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":88,"publishedAt":36},"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",[85],{"categoryNo":86,"categoryName":87,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[89,90,91,92,93,94],"skill sync","sync","metadata","cloud","prowler","auto",{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":102,"publishedAt":36},"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",[101],{"categoryNo":86,"categoryName":87,"taxonomyType":21,"taxonomyTypeDesc":22},[103,104,105,106,92,93,107,108,109,110,111,112,113,114,115],"skill creator","spec","ai agent","create","Bash","grep","read","write","edit","instructions","user","webfetch","add agent",{"skillNo":117,"name":118,"nameZh":6,"description":119,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":120,"categories":121,"keywords":126,"publishedAt":36},"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",[122,125],{"categoryNo":123,"categoryName":124,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000009","前端开发",{"categoryNo":86,"categoryName":87,"taxonomyType":21,"taxonomyTypeDesc":22},[127,128,129,130,131,132,133,134,113,135,35],"skill commit","commit","frontend","git commit","code","git","commits","format","landing",{"skillNo":137,"name":138,"nameZh":6,"description":139,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":140,"categories":141,"keywords":142,"publishedAt":36},"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",[],[143,144,145,146,147],"project info","component","monorepo","context","overview",{"skillNo":149,"name":150,"nameZh":6,"description":151,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":152,"categories":153,"keywords":160,"publishedAt":36},"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",[154,155],{"categoryNo":123,"categoryName":124,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":156,"categoryName":157,"taxonomyType":158,"taxonomyTypeDesc":159},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[161,146,129,162,131,163,164,165,166,167,168],"frontend context","components","js","api","integration","frontend architecture","Next.js","architecture",{"skillNo":170,"name":171,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":172,"licenseFileUrl":6,"sourceHtmlUrl":173,"categories":174,"keywords":176,"publishedAt":36},"01M6C2DCXFSYWZCQWMPGWWQJQ7","backend-service","MIT","https:\u002F\u002Fgithub.com\u002Fdavidleonmayor\u002Fproyecto-grado-unimayor\u002Fblob\u002Fmain\u002Fskills\u002Fbackend-service\u002FSKILL.md",[175],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[177,35],"backend service"]