avajs/ava · error · TypeError
`t.try()` titles must be strings
Error message
`t.try()` titles must be strings
What it means
The optional title given to t.try() must be a string. AVA parses the title from the arguments; if a non-string truthy value is passed in the title position (e.g. a number or object) and it cannot be interpreted as a valid title, this TypeError is thrown.
Source
Thrown at lib/test.js:114
if (test.isHook) {
const error = new Error('`t.try()` can only be used in tests');
test.saveFirstError(error);
throw error;
}
const {args, implementation, title} = parseTestArgs(attemptArgs);
if (typeof implementation !== 'function') {
throw new TypeError('Expected an implementation.');
}
let attemptTitle;
if (!title.isSet || title.isEmpty) {
attemptTitle = `${test.title} ─ attempt ${test.attemptCount + 1}`;
} else if (title.isValid) {
attemptTitle = `${test.title} ─ ${title.value}`;
} else {
throw new TypeError('`t.try()` titles must be strings');
}
if (!test.registerUniqueTitle(attemptTitle)) {
throw new Error(`Duplicate test title: ${attemptTitle}`);
}
let committed = false;
let discarded = false;
const {assertCount, deferredSnapshotRecordings, errors, logs, passed, snapshotCount, startingSnapshotCount} = await test.runAttempt(attemptTitle, t => implementation(t, ...args));
return {
errors,
logs: [...logs], // Don't allow modification of logs.
passed,
title: attemptTitle,
commit({retainLogs = true} = {}) {
if (committed) {View on GitHub (pinned to bbfd946322)
Solutions
- Pass the title as a string: t.try('my title', impl).
- Remove the title entirely and let AVA generate 'attempt N' automatically.
- Add a type check or TypeScript annotation so the title is always string.
Example fix
// before
const attempt = t.try(123, impl);
// after
const attempt = t.try('attempt 123', impl); Defensive patterns
Strategy: type-guard
Validate before calling
if (title !== undefined && typeof title !== 'string') throw new TypeError('t.try() title must be a string'); Type guard
const isValidTitle = (v) => v === undefined || typeof v === 'string';
Prevention
- Quote titles as string literals
- Avoid computing titles from non-string data without String() coercion
- Type title params as string | undefined in helper wrappers
When it happens
Trigger: t.try(42, impl) or t.try({label: 'x'}, impl) — a non-string first argument that is not a function; passing a title that is not a string or a function in the t.try(title, implementation, ...args) overload.
Common situations: Using template variables that resolved to a number; copying macros that accept titles as objects; TypeScript projects where `any` suppressed the type error until runtime.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Expected an implementation.
- Expected an implementation. Use `test.todo()` for tests with
- Test & hook titles must be strings
- Tests must have a title
- Cannot record snapshot ${index} for ${JSON.stringify(belongs
AI-assisted analysis of avajs/ava@bbfd946322 (2026-09-02).
Data as JSON: /api/errors/1591451a07587576.
Report an issue: GitHub.