(
query: (container: HTMLElement, ...args: Arguments) => HTMLElement[],
queryAllByName: string,
variant: Variant,
)
| 165 | |
| 166 | const wrapAllByQueryWithSuggestion = |
| 167 | < |
| 168 | // We actually want `Arguments extends [args: ...unknown[], options?: Options]` |
| 169 | // But that's not supported by TS so we have to `@ts-expect-error` every callsite |
| 170 | Arguments extends [...unknown[], WithSuggest], |
| 171 | >( |
| 172 | query: (container: HTMLElement, ...args: Arguments) => HTMLElement[], |
| 173 | queryAllByName: string, |
| 174 | variant: Variant, |
| 175 | ) => |
| 176 | (container: HTMLElement, ...args: Arguments) => { |
| 177 | const els = query(container, ...args) |
| 178 | |
| 179 | const [{suggest = getConfig().throwSuggestions} = {}] = args.slice(-1) as [ |
| 180 | WithSuggest, |
| 181 | ] |
| 182 | if (els.length && suggest) { |
| 183 | // get a unique list of all suggestion messages. We are only going to make a suggestion if |
| 184 | // all the suggestions are the same |
| 185 | const uniqueSuggestionMessages = [ |
| 186 | ...new Set( |
| 187 | els.map( |
| 188 | element => |
| 189 | getSuggestedQuery(element, variant)?.toString() as string, |
| 190 | ), |
| 191 | ), |
| 192 | ] |
| 193 | |
| 194 | if ( |
| 195 | // only want to suggest if all the els have the same suggestion. |
| 196 | uniqueSuggestionMessages.length === 1 && |
| 197 | !queryAllByName.endsWith( |
| 198 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- TODO: Can this be null at runtime? |
| 199 | getSuggestedQuery(els[0], variant)!.queryName as string, |
| 200 | ) |
| 201 | ) { |
| 202 | throw getSuggestionError(uniqueSuggestionMessages[0], container) |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | return els |
| 207 | } |
| 208 | |
| 209 | // TODO: This deviates from the published declarations |
| 210 | // However, the implementation always required a dyadic (after `container`) not variadic `queryAllBy` considering the implementation of `makeFindQuery` |
no test coverage detected