{"record":{"id":"bab939eafb329a3a","repo":"denoland/deno","slug":"err-invalid-return-value-bab939","errorCode":"ERR_INVALID_RETURN_VALUE","errorMessage":"Expected instance of Promise to be returned from the \"promiseFn\" function but got ${resultPromise}.","messagePattern":"Expected instance of Promise to be returned from the \"promiseFn\" function but got (.+?)\\.","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/assert.ts","lineNumber":353,"sourceCode":"  // Accept native ES6 promises and promises that are implemented in a similar\n  // way. Do not accept thenables that use a function as `obj` and that have no\n  // `catch` handler.\n  return isPromise(obj) ||\n    (obj !== null && typeof obj === \"object\" &&\n      typeof obj.then === \"function\" &&\n      typeof obj.catch === \"function\");\n}\n\nasync function waitForActual(\n  promiseFn,\n) {\n  let resultPromise;\n  if (typeof promiseFn === \"function\") {\n    // Return a rejected promise if `promiseFn` throws synchronously.\n    resultPromise = promiseFn();\n    // Fail in case no promise is returned.\n    if (!checkIsPromise(resultPromise)) {\n      throw new ERR_INVALID_RETURN_VALUE(\n        \"instance of Promise\",\n        \"promiseFn\",\n        resultPromise,\n      );\n    }\n  } else if (checkIsPromise(promiseFn)) {\n    resultPromise = promiseFn;\n  } else {\n    throw new ERR_INVALID_ARG_TYPE(\n      \"promiseFn\",\n      [\"Function\", \"Promise\"],\n      promiseFn,\n    );\n  }\n\n  try {\n    await resultPromise;\n  } catch (e) {","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/assert.ts#L335-L371","documentation":"Thrown by assert.rejects() and assert.doesNotReject() when the first argument is a function whose return value is not a Promise. waitForActual() invokes promiseFn() and immediately checks the result with checkIsPromise(); a plain value (including the undefined returned by a non-async function) fails that check, so the error is raised before any assertion logic runs.","triggerScenarios":"assert.rejects(() => { throw new Error('boom'); }) (the callback throws synchronously and returns undefined); assert.doesNotReject(() => 42); passing any non-async helper that returns a plain value where a promise-returning function is expected.","commonSituations":"Using the async assertion helpers on synchronous code; forgetting the async keyword on a test helper; refactoring a function from async to sync without updating assert.rejects call sites.","solutions":["Make the callback async: assert.rejects(async () => { ... }) so it returns a rejected Promise","Return a Promise explicitly from the callback (return Promise.reject(new Error(...)))","Use assert.throws() instead when testing synchronous exceptions","Pass a Promise directly as the first argument rather than a function"],"exampleFix":"// before\nassert.rejects(() => { throw new Error('boom'); });\n// after\nassert.rejects(async () => { throw new Error('boom'); });\n// or, for synchronous code\nassert.throws(() => { throw new Error('boom'); });","handlingStrategy":"validation","validationCode":"// Wrap the target so it always settles as a Promise\nconst settle = (fn) => async () => fn();\nawait assert.rejects(settle(syncFn), /boom/);","typeGuard":"const isPromise = (v) => v != null && typeof v.then === 'function' && typeof v.catch === 'function';","tryCatchPattern":"try { await assert.rejects(fn, /boom/); } catch (e) { if (e.code === 'ERR_INVALID_RETURN_VALUE') throw new Error('pass an async function or a Promise to assert.rejects'); throw e; }","preventionTips":["Default to async () => ... callbacks in assert.rejects/assert.doesNotReject","Reserve assert.throws for synchronous code","Lint against non-async function arguments passed to the async assert helpers"],"tags":["assert","testing","async","promise","node-compat"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}