{"record":{"id":"ac2a3c9c6bf1c44c","repo":"angular/angular","slug":"automatic-conversion-to-format-is-not-supported-ac2a3c","errorCode":null,"errorMessage":"Automatic conversion to ${format} is not supported for response type.","messagePattern":"Automatic conversion to (.+?) is not supported for response type\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/common/http/testing/src/request.ts","lineNumber":207,"sourceCode":"    | (boolean | string | number | Object | null)[],\n  format: string = 'JSON',\n): Object | string | number | (Object | string | number)[] {\n  if (typeof ArrayBuffer !== 'undefined' && body instanceof ArrayBuffer) {\n    throw new Error(`Automatic conversion to ${format} is not supported for ArrayBuffers.`);\n  }\n  if (typeof Blob !== 'undefined' && body instanceof Blob) {\n    throw new Error(`Automatic conversion to ${format} is not supported for Blobs.`);\n  }\n  if (\n    typeof body === 'string' ||\n    typeof body === 'number' ||\n    typeof body === 'object' ||\n    typeof body === 'boolean' ||\n    Array.isArray(body)\n  ) {\n    return body;\n  }\n  throw new Error(`Automatic conversion to ${format} is not supported for response type.`);\n}\n\n/**\n * Helper function to convert a response body to a string.\n */\nfunction _toTextBody(\n  body: ArrayBuffer | Blob | string | number | Object | (string | number | Object | null)[],\n): string {\n  if (typeof body === 'string') {\n    return body;\n  }\n  if (typeof ArrayBuffer !== 'undefined' && body instanceof ArrayBuffer) {\n    throw new Error('Automatic conversion to text is not supported for ArrayBuffers.');\n  }\n  if (typeof Blob !== 'undefined' && body instanceof Blob) {\n    throw new Error('Automatic conversion to text is not supported for Blobs.');\n  }\n  return JSON.stringify(_toJsonBody(body, 'text'));","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/angular/angular/blob/51cb07e98081ab7e4e84a9e0949266a8e19cca84/packages/common/http/testing/src/request.ts#L189-L225","documentation":"Thrown by the HttpClient testing backend when the flushed body's runtime type matches none of string/number/object/boolean/array — i.e. `undefined`, a function, a symbol, or a bigint. The usual culprit is `flush(undefined)`: a variable that was never assigned. `null` is fine because `_maybeConvertBody` short-circuits it to a null body (with automatic status 204 when no status is given).","triggerScenarios":"`req.flush(undefined)` in a spec (e.g. `req.flush(response.body)` where `response.body` was never set); flushing a function or bigint value into a json/text request.","commonSituations":"Optional fixture fields left unset; a helper that returns undefined for an empty payload; refactoring mocks so the body variable is conditionally populated.","solutions":["Flush `null` for empty bodies: `req.flush(body ?? null)` — null is valid and yields a 204","Flush a concrete empty representation (empty string, `{}`, `[]`) if the code under test expects a body","Check the fixture: make sure the variable passed to flush() is actually assigned"],"exampleFix":"// before\nconst body = response?.body; // undefined\nreq.flush(body); // throws\n\n// after\nreq.flush(body ?? null); // null body, status 204","handlingStrategy":"validation","validationCode":"// Guard against accidentally flushing undefined\nif (body === undefined) {\n  throw new Error('flush(undefined) is not supported — use null for an empty body');\n}\nreq.flush(body ?? null);","typeGuard":"const isFlushableBody = (b: unknown): b is string | number | boolean | object | null => b === null || !['undefined', 'function', 'symbol', 'bigint'].includes(typeof b);","tryCatchPattern":null,"preventionTips":["Normalize with `req.flush(body ?? null)` when the body is conditionally populated","Type mock fixtures explicitly (body: MyDto | null) so undefined cannot sneak in","Flush concrete empty representations ({}, '', []) when the code under test expects a body"],"tags":["testing","http-client","undefined","validation"],"backgroundTag":"mock-response-type-mismatch","analyzedSha":"51cb07e98081ab7e4e84a9e0949266a8e19cca84","analyzedAt":"2026-08-22T07:04:54.531Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}