{"record":{"id":"62a956ec9a33b5a6","repo":"avajs/ava","slug":"t-like-selector-must-be-a-non-empty-object","errorCode":null,"errorMessage":"`t.like()` selector must be a non-empty object","messagePattern":"`t\\.like\\(\\)` selector must be a non-empty object","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":365,"sourceCode":"\t\t\tassertMessage(message, 't.notDeepEqual()');\n\n\t\t\tconst result = concordance.compare(actual, expected, concordanceOptions);\n\t\t\tif (result.pass) {\n\t\t\t\tconst actualDescriptor = result.actual ?? concordance.describe(actual, concordanceOptions);\n\t\t\t\tthrow fail(new AssertionError(message, {\n\t\t\t\t\tassertion: 't.notDeepEqual()',\n\t\t\t\t\tformattedDetails: [formatDescriptorWithLabel('Value is deeply equal:', actualDescriptor)],\n\t\t\t\t}));\n\t\t\t}\n\n\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}","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L347-L383","documentation":"t.like(actual, selector) compares actual against a subset selector object. Before comparing, AVA validates the selector with isLikeSelector; if it is not a non-empty plain object, AVA throws an AssertionError with the fixed message '`t.like()` selector must be a non-empty object' and a 'Called with:' detail (lib/assert.js:365).","triggerScenarios":"Calling t.like(actual, selector) where selector is undefined, null, a primitive (string/number/boolean), an array, an empty object {}, or a non-plain object (e.g. a class instance used as the selector).","commonSituations":"Variable holding the expected subset is accidentally undefined (typo, failed lookup), passing an empty object intending 'match anything', passing a deeply nested value extracted with optional chaining that resolved to null, or swapping the argument order so the actual value lands in the selector slot.","solutions":["Ensure the second argument is a non-empty plain object of expected properties: t.like(user, { name: 'Ada' }).","Check argument order — the selector is the second parameter; if you passed actual twice, correct the call.","If the selector is computed, guard against empty/undefined before calling: only invoke t.like when Object.keys(selector).length > 0."],"exampleFix":"// before\nt.like(user, filter); // filter is undefined when no filter is given\n\n// after\nif (filter && Object.keys(filter).length > 0) {\n  t.like(user, filter);\n} else {\n  t.pass();\n}","handlingStrategy":"validation","validationCode":"function isLikeSelector(s) {\n  return s !== null && typeof s === 'object' && !Array.isArray(s) && Object.keys(s).length > 0;\n}\nif (!isLikeSelector(selector)) throw new TypeError('t.like() selector must be a non-empty object');","typeGuard":"const isLikeSelector = (s) => s !== null && typeof s === 'object' && !Array.isArray(s) && Object.getPrototypeOf(s) === Object.prototype && Object.keys(s).length > 0;","tryCatchPattern":null,"preventionTips":["Always pass a literal or validated non-empty object as the second argument to t.like.","Double-check argument order: t.like(actual, selector).","Guard computed selectors against undefined/null/empty before calling the assertion."],"tags":["ava","assertions","t-like","argument-validation"],"backgroundTag":"invalid-assertion-selector","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}