{"record":{"id":"be6e767133f6c0e6","repo":"hoppscotch/hoppscotch","slug":"charset-expects-a-string-value-typically-conten","errorCode":null,"errorMessage":"charset() expects a string value (typically Content-Type header)","messagePattern":"charset\\(\\) expects a string value \\(typically Content-Type header\\)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/hoppscotch-js-sandbox/src/bootstrap-code/post-request.js","lineNumber":1822,"sourceCode":"                if (error) return `Item [${i}]: ${error}`\n              }\n            }\n          }\n\n          return null // Validation passed\n        }\n\n        const error = validateSchema(expectVal, schema)\n        if (error) {\n          throw new Error(`JSON Schema validation failed: ${error}`)\n        }\n        return withModifiers(modifiers)\n      }\n\n      proxy.charset = (expectedCharset) => {\n        // expectVal should be a string (typically Content-Type header)\n        if (typeof expectVal !== \"string\") {\n          throw new Error(\n            \"charset() expects a string value (typically Content-Type header)\"\n          )\n        }\n\n        const lowerExpected = expectedCharset.toLowerCase()\n        const lowerActual = expectVal.toLowerCase()\n\n        if (!lowerActual.includes(lowerExpected)) {\n          throw new Error(\n            `Expected charset \"${expectedCharset}\" not found in \"${expectVal}\"`\n          )\n        }\n        return withModifiers(modifiers)\n      }\n\n      proxy.cookie = (cookieName, cookieValue) => {\n        // This works when expectVal is pm.response or similar\n        // For the Chai extension, we need to check if cookies exist","sourceCodeStart":1804,"sourceCodeEnd":1840,"githubUrl":"https://github.com/hoppscotch/hoppscotch/blob/1acb8a3a7581e4db32ba0d529170c4669a2e1053/packages/hoppscotch-js-sandbox/src/bootstrap-code/post-request.js#L1804-L1840","documentation":"Thrown by the Postman-compatible `charset()` assertion on the chai proxy (`pm.expect(value).to.have.charset(expected)`). It fires when `expectVal` is not a string — `charset()` expects the value under test to be a string (typically the Content-Type header). Any non-string `expectVal` (number, object, undefined, null) triggers it.","triggerScenarios":"Calling `.charset(...)` on a chai assertion whose `expectVal` is not a string — e.g. `pm.expect(pm.response).to.have.charset('utf-8')` (object) or `pm.expect(123).to.have.charset('utf-8')` instead of `pm.expect(pm.response.headers['content-type']).to.have.charset('utf-8')`.","commonSituations":"Passing the response object instead of the Content-Type header value, asserting before headers are populated, or a typo in the chai chain that leaves `expectVal` as a non-string.","solutions":["Pass the Content-Type header string as `expectVal`, not the response object.","Confirm the header exists before asserting (guard against undefined).","Use the correct chai chain so `expectVal` resolves to a string.","Switch to a header-specific assertion if you actually need the full header."],"exampleFix":"// before\npm.expect(pm.response).to.have.charset(\"utf-8\") // response is an object\n\n// after\npm.expect(pm.response.headers[\"content-type\"]).to.have.charset(\"utf-8\")","handlingStrategy":"type-guard","validationCode":"const ct = pm.response.headers[\"content-type\"]\nif (typeof ct !== \"string\") throw new Error(\"content-type header is not a string\")\npm.expect(ct).to.have.charset(\"utf-8\")","typeGuard":"function isString(v: unknown): v is string { return typeof v === \"string\" }","tryCatchPattern":"// assertion error surfaced by the sandbox test runner","preventionTips":["Pass the Content-Type header string as expectVal, not the response object.","Guard against undefined headers before asserting.","Use the correct chai chain so expectVal is a string."],"tags":["sandbox","post-request","test-assertion","charset","chai"],"backgroundTag":null,"analyzedSha":"1acb8a3a7581e4db32ba0d529170c4669a2e1053","analyzedAt":"2026-08-12T11:34:52.648Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}