{"record":{"id":"caa8282ada554dfe","repo":"grafana/k6","slug":"the-argument-to-is-must-be-a-function-a-selecto","errorCode":null,"errorMessage":"the argument to is() must be a function, a selector or a selection","messagePattern":"the argument to is\\(\\) must be a function, a selector or a selection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"js/modules/k6/html/html.go","lineNumber":410,"sourceCode":"\tif !isFn {\n\t\tcommon.Throw(s.rt, errors.New(\"the argument to filter() must be a function, a selector or a selection\"))\n\t}\n\n\treturn Selection{s.rt, s.sel.FilterFunction(s.buildMatcher(v, sobekFn)), s.URL}\n}\n\nfunc (s Selection) Is(v sobek.Value) bool {\n\tswitch val := v.Export().(type) {\n\tcase string:\n\t\treturn s.sel.Is(val)\n\n\tcase Selection:\n\t\treturn s.sel.IsSelection(val.sel)\n\n\tdefault:\n\t\tsobekFn, isFn := sobek.AssertFunction(v)\n\t\tif !isFn {\n\t\t\tcommon.Throw(s.rt, errors.New(\"the argument to is() must be a function, a selector or a selection\"))\n\t\t}\n\n\t\treturn s.sel.IsFunction(s.buildMatcher(v, sobekFn))\n\t}\n}\n\n// Map implements ES5 Array.prototype.map\nfunc (s Selection) Map(v sobek.Value) []sobek.Value {\n\tsobekFn, isFn := sobek.AssertFunction(v)\n\tif !isFn {\n\t\tcommon.Throw(s.rt, errors.New(\"the argument to map() must be a function\"))\n\t}\n\n\tvar values []sobek.Value\n\ts.sel.Each(func(idx int, sel *goquery.Selection) {\n\t\tselection := &Selection{sel: sel, URL: s.URL, rt: s.rt}\n\n\t\tif fnRes, fnErr := sobekFn(v, s.rt.ToValue(idx), s.rt.ToValue(selection)); fnErr == nil {","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/js/modules/k6/html/html.go#L392-L428","documentation":"Selection.Is() in k6's HTML module checks whether the current selection matches a CSS selector, another Selection, or a predicate function, and throws when the argument is none of these. The type switch handles string and Selection; the default branch asserts a function via sobek.AssertFunction before calling goquery's IsFunction.","triggerScenarios":"Calling is() with a DOM Element, null, undefined, a boolean, or any other non-string/non-Selection/non-function value.","commonSituations":"Comparing a selection against an element variable; forgetting the argument in a quick REPL test; chaining is() after a call that already returned a boolean.","solutions":["Pass a selector: sel.is('.visible')","Or a Selection to test overlap: sel.is(otherSel)","Or a function: sel.is((idx, el) => el.attr('aria-hidden') !== 'true')"],"exampleFix":"// before\nif (selection.is(element)) { ... }\n\n// after\nif (selection.is((idx, el) => el.id() === element.id())) { ... }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"const isIsArg = (v) => typeof v === 'string' || typeof v === 'function' ||\n  (v !== null && typeof v === 'object' && typeof v.sel !== 'undefined');\nif (!isIsArg(arg)) throw new TypeError('is() expects selector, Selection, or function');\nsel.is(arg);","tryCatchPattern":null,"preventionTips":["Use selector strings for class/tag checks with is()","Compare elements via id/attribute inside a predicate function","Guard dynamic arguments with a typeof check"],"tags":["javascript","html","dom","matching","k6-html"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}