{"record":{"id":"be9e34f7a72ae40d","repo":"nodejs/node","slug":"und-err-invalid-arg-be9e34","errorCode":"UND_ERR_INVALID_ARG","errorMessage":"Argument opts.agent must implement Agent","messagePattern":"Argument opts\\.agent must implement Agent","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/mock/mock-pool.js","lineNumber":26,"sourceCode":"  kMockAgent,\n  kClose,\n  kOriginalClose,\n  kOrigin,\n  kOriginalDispatch,\n  kConnected,\n  kIgnoreTrailingSlash\n} = require('./mock-symbols')\nconst { MockInterceptor } = require('./mock-interceptor')\nconst Symbols = require('../core/symbols')\nconst { InvalidArgumentError } = require('../core/errors')\n\n/**\n * MockPool provides an API that extends the Pool to influence the mockDispatches.\n */\nclass MockPool extends Pool {\n  constructor (origin, opts) {\n    if (!opts || !opts.agent || typeof opts.agent.dispatch !== 'function') {\n      throw new InvalidArgumentError('Argument opts.agent must implement Agent')\n    }\n\n    super(origin, opts)\n\n    this[kMockAgent] = opts.agent\n    this[kOrigin] = origin\n    this[kIgnoreTrailingSlash] = opts.ignoreTrailingSlash ?? false\n    this[kDispatches] = []\n    this[kConnected] = 1\n    this[kOriginalDispatch] = this.dispatch\n    this[kOriginalClose] = this.close.bind(this)\n\n    this.dispatch = buildMockDispatch.call(this)\n    this.close = this[kClose]\n  }\n\n  get [Symbols.kConnected] () {\n    return this[kConnected]","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/mock/mock-pool.js#L8-L44","documentation":"Thrown by the MockPool constructor when opts is missing, opts.agent is missing, or opts.agent.dispatch is not a function. MockPool extends Pool and requires the parent MockAgent to coordinate unmatched dispatches and share state; the agent is duck-typed on the presence of a dispatch method. Identical guard to MockClient's constructor.","triggerScenarios":"Constructing `new MockPool(origin)` with no opts, opts without agent, or a custom object lacking dispatch. Most commonly hit when instantiating MockPool directly instead of via mockAgent.get(origin) (which returns MockClient or MockPool based on the agent's pooling config).","commonSituations":"Manually new-ing MockPool in a test instead of using MockAgent.get; passing a real Pool/Agent where a MockAgent was expected; refactoring that drops the agent option.","solutions":["Obtain a pool through the MockAgent: const pool = mockAgent.get('http://localhost:3000').","If constructing manually, pass the MockAgent: new MockPool(origin, { agent: mockAgent }).","Ensure the agent is a MockAgent instance exposing dispatch."],"exampleFix":"// before\nconst pool = new MockPool('http://localhost:3000')\n\n// after\nconst mockAgent = new MockAgent()\nconst pool = mockAgent.get('http://localhost:3000')\n// or\nconst pool = new MockPool('http://localhost:3000', { agent: mockAgent })","handlingStrategy":"validation","validationCode":"function getMockPool(mockAgent, origin) {\n  if (!mockAgent || typeof mockAgent.dispatch !== 'function') {\n    throw new TypeError('Provide a MockAgent instance');\n  }\n  return mockAgent.get(origin);\n}","typeGuard":"function isAgentLike(v) {\n  return v != null && typeof v.dispatch === 'function';\n}","tryCatchPattern":null,"preventionTips":["Obtain pools via mockAgent.get(origin) rather than new MockPool(...).","Always pass { agent: mockAgent } when constructing manually.","Share a single MockAgent across the test file."],"tags":["undici","mock","validation","constructor","agent","pool"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}