{"record":{"id":"8a57212cb485eb0a","repo":"angular/angular","slug":"automatic-conversion-to-text-is-not-supported-for-8a5721","errorCode":null,"errorMessage":"Automatic conversion to text is not supported for Blobs.","messagePattern":"Automatic conversion to text is not supported for Blobs\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/common/http/testing/src/request.ts","lineNumber":223,"sourceCode":"    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'));\n}\n\n/**\n * Convert a response body to the requested type.\n */\nfunction _maybeConvertBody(\n  responseType: string,\n  body: ArrayBuffer | Blob | string | number | Object | (string | number | Object | null)[] | null,\n): ArrayBuffer | Blob | string | number | Object | (string | number | Object | null)[] | null {\n  if (body === null) {\n    return null;\n  }\n  switch (responseType) {\n    case 'arraybuffer':\n      return _toArrayBufferBody(body);\n    case 'blob':","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/angular/angular/blob/51cb07e98081ab7e4e84a9e0949266a8e19cca84/packages/common/http/testing/src/request.ts#L205-L241","documentation":"Thrown by the HttpClient testing backend when a request with `responseType: 'text'` is flushed with a `Blob`. `_toTextBody()` rejects Blobs (and ArrayBuffers) because it cannot decode binary content to a string without charset knowledge; only strings pass through, and other primitive/object values are JSON.stringify'd.","triggerScenarios":"In a spec: `httpClient.get('/log', {responseType: 'text'})` then `req.flush(new Blob(['line1']))`.","commonSituations":"Reusing Blob fixtures in text-response tests; simulating text downloads as binary.","solutions":["Flush a string: `req.flush('line1')`","If the consumer really reads a Blob, change the request to `responseType: 'blob'`"],"exampleFix":"// before\nhttpClient.get('/log', {responseType: 'text'}).subscribe();\nreq.flush(new Blob(['line1'])); // throws\n\n// after\nreq.flush('line1');","handlingStrategy":"validation","validationCode":"if (req.request.responseType === 'text' && body instanceof Blob) {\n  throw new Error('Flush a string for responseType text');\n}\nreq.flush(body as any);","typeGuard":"const isTextFlushBody = (b: unknown): b is string => typeof b === 'string';","tryCatchPattern":null,"preventionTips":["Do not hand Blob fixtures to text-response specs","If the component really consumes a Blob, test it with responseType 'blob' instead"],"tags":["testing","http-client","blob","text"],"backgroundTag":"mock-response-type-mismatch","analyzedSha":"51cb07e98081ab7e4e84a9e0949266a8e19cca84","analyzedAt":"2026-08-22T07:04:54.531Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}