{"record":{"id":"01e5a7f81824d3cc","repo":"avajs/ava","slug":"t-like-selector-must-not-contain-circular-refe","errorCode":null,"errorMessage":"`t.like()` selector must not contain circular references","messagePattern":"`t\\.like\\(\\)` selector must not contain circular references","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":376,"sourceCode":"\t\t\treturn pass();\n\t\t});\n\n\t\tthis.like = withSkip((actual, selector, message) => {\n\t\t\tassertMessage(message, 't.like()');\n\n\t\t\tif (!isLikeSelector(selector)) {\n\t\t\t\tthrow fail(new AssertionError('`t.like()` selector must be a non-empty object', {\n\t\t\t\t\tassertion: 't.like()',\n\t\t\t\t\tformattedDetails: [formatWithLabel('Called with:', selector)],\n\t\t\t\t}));\n\t\t\t}\n\n\t\t\tlet comparable;\n\t\t\ttry {\n\t\t\t\tcomparable = selectComparable(actual, selector);\n\t\t\t} catch (error) {\n\t\t\t\tif (error === CIRCULAR_SELECTOR) {\n\t\t\t\t\tthrow fail(new AssertionError('`t.like()` selector must not contain circular references', {\n\t\t\t\t\t\tassertion: 't.like()',\n\t\t\t\t\t\tformattedDetails: [formatWithLabel('Called with:', selector)],\n\t\t\t\t\t}));\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tconst result = concordance.compare(comparable, selector, concordanceOptions);\n\t\t\tif (result.pass) {\n\t\t\t\treturn pass();\n\t\t\t}\n\n\t\t\tconst actualDescriptor = result.actual ?? concordance.describe(comparable, concordanceOptions);\n\t\t\tconst expectedDescriptor = result.expected ?? concordance.describe(selector, concordanceOptions);\n\t\t\tthrow fail(new AssertionError(message, {\n\t\t\t\tassertion: 't.like()',\n\t\t\t\tformattedDetails: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)],","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L358-L394","documentation":"This AVA assertion error is thrown by t.like() when the selector object contains circular references. t.like() walks the selector via selectComparable() to pick the comparable subset of actual; a circular selector makes that walk impossible, so the library detects it (CIRCULAR_SELECTOR sentinel) and throws a fixed usage message instead of letting the walk blow the stack. The selector must be an acyclic plain object.","triggerScenarios":"Calling t.like(actual, selector) where the selector (or a nested value inside it) references itself directly or indirectly, e.g. const sel = {a: 1}; sel.self = sel; t.like(obj, sel).","commonSituations":"Building the selector by mutation where a property is accidentally assigned back the selector itself; reusing an object that another object points back to; copying config objects that contain parent links.","solutions":["Inspect the selector printed under 'Called with:' and remove or restructure the self-referencing property.","If you need to assert on a circular actual value, pass only the non-cyclic subset as the selector.","Restructure the selector as a fresh literal containing only the fields you want matched."],"exampleFix":"// before\nconst selector = { name: 'x' };\nselector.parent = selector; // circular\nt.like(value, selector);\n// after\nconst selector = { name: 'x' };\nt.like(value, selector);","handlingStrategy":"validation","validationCode":"function hasCircular(obj, seen = new Set()) {\n  if (obj === null || typeof obj !== 'object') return false;\n  if (seen.has(obj)) return true;\n  seen.add(obj);\n  return Object.values(obj).some(v => hasCircular(v, seen));\n}\n// before calling: if (hasCircular(selector)) throw new Error('selector is circular');","typeGuard":"const isAcyclicSelector = (s) => typeof s === 'object' && s !== null && !hasCircular(s);","tryCatchPattern":"try {\n  t.like(actual, selector);\n} catch (err) {\n  if (/circular references/.test(err.message)) {\n    t.fail('selector passed to t.like() is circular: ' + describe(selector));\n  } else { throw err; }\n}","preventionTips":["Build selectors as fresh object literals, never mutated self-referencing objects.","Run a cycle-detecting helper (e.g. hasCircular) on dynamically built selectors.","Avoid copying objects with parent/back-pointers into selectors."],"tags":["assertion","ava","circular-reference","usage-error"],"backgroundTag":"circular-reference-in-selector","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}