{"record":{"id":"6c267f1b7bc9de6f","repo":"avajs/ava","slug":"t-notthrowsasync-must-be-called-with-a-functio","errorCode":null,"errorMessage":"`t.notThrowsAsync()` must be called with a function or promise","messagePattern":"`t\\.notThrowsAsync\\(\\)` must be called with a function or promise","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":586,"sourceCode":"\t\t\t\t}));\n\t\t\t}\n\n\t\t\treturn pass();\n\t\t});\n\n\t\tthis.notThrowsAsync = withSkip(async (nonThrower, message) => {\n\t\t\ttry {\n\t\t\t\tassertMessage(message, 't.notThrowsAsync()');\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait nonThrower;\n\t\t\t\t} catch {}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tif (typeof nonThrower !== 'function' && !isPromise(nonThrower)) {\n\t\t\t\tthrow fail(new AssertionError('`t.notThrowsAsync()` must be called with a function or promise', {\n\t\t\t\t\tassertion: 't.notThrowsAsync()',\n\t\t\t\t\tformattedDetails: [formatWithLabel('Called with:', nonThrower)],\n\t\t\t\t}));\n\t\t\t}\n\n\t\t\tconst handlePromise = async (promise, wasReturned) => {\n\t\t\t\t// Create an error object to record the stack before it gets lost in the promise chain.\n\t\t\t\tconst assertionStack = getAssertionStack();\n\t\t\t\t// Handle \"promise like\" objects by casting to a real Promise.\n\t\t\t\tconst intermediate = Promise.resolve(promise).then(noop, error => {\n\t\t\t\t\tthrow failPending(new AssertionError(message, {\n\t\t\t\t\t\tassertion: 't.notThrowsAsync()',\n\t\t\t\t\t\tassertionStack,\n\t\t\t\t\t\tformattedDetails: [formatWithLabel(`${wasReturned ? 'Returned promise' : 'Promise'} rejected with:`, error)],\n\t\t\t\t\t}));\n\t\t\t\t});\n\t\t\t\tpending(intermediate, assertionStack);\n","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L568-L604","documentation":"t.notThrowsAsync() asserts that a function returning a promise (or a promise itself) does not reject. AVA validates its argument up front and throws this AssertionError when it is neither a function nor a promise-like object. Like other improperUsage errors, it signals a mistake in how the assertion was invoked.","triggerScenarios":"Passing an awaited value (the resolved result) instead of the promise; passing a plain value, number, or string; passing a function to t.notThrowsAsync that is meant for t.notThrows without returning a promise while also failing the type check because a non-callable was given.","commonSituations":"Writing t.notThrowsAsync(await asyncFn()) — the await removes the promise; confusing t.notThrows and t.notThrowsAsync during refactors; passing null/undefined due to an earlier failed lookup.","solutions":["Pass the promise directly: t.notThrowsAsync(asyncFn()) without await","Or pass a function returning a promise: t.notThrowsAsync(() => asyncFn())","If the code is synchronous, use t.notThrows(() => syncFn()) instead"],"exampleFix":"// before\nawait t.notThrowsAsync(await fetchUser(id));\n// after\nawait t.notThrowsAsync(fetchUser(id));","handlingStrategy":"type-guard","validationCode":"const arg = asyncFn();\nif (typeof arg !== 'function' && !(arg && typeof arg.then === 'function')) {\n  throw new TypeError('notThrowsAsync needs a function or a promise — remove any await');\n}","typeGuard":"const isFunctionOrPromise = (v) =>\n  typeof v === 'function' ||\n  (v !== null && typeof v === 'object' && typeof v.then === 'function');","tryCatchPattern":"try {\n  await t.notThrowsAsync(promiseOrFn);\n} catch (e) {\n  if (/must be called with a function or promise/.test(e.message)) {\n    throw new TypeError('Do not await before passing: t.notThrowsAsync(asyncFn())');\n  }\n  throw e;\n}","preventionTips":["Never write t.notThrowsAsync(await fn())","Pass either the promise or a zero-arg function returning a promise","Use async functions so non-promise returns are impossible"],"tags":["ava","assertion","promise","usage"],"backgroundTag":"assertion-invalid-argument","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}