{"record":{"id":"4978c737272e52ce","repo":"angular/components","slug":"could-not-find-tile-at-given-position","errorCode":null,"errorMessage":"Could not find tile at given position.","messagePattern":"Could not find tile at given position\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/material/grid-list/testing/grid-list-harness.ts","lineNumber":86,"sourceCode":"    // The tile coordinator respects the colspan and rowspan for calculating the positions\n    // of tiles, but it does not create multiple position entries if a tile spans over multiple\n    // columns or rows. We want to provide an API where developers can retrieve a tile based on\n    // any position that lies within the visual tile boundaries. For example: If a tile spans\n    // over two columns, then the same tile should be returned for either column indices.\n    for (let i = 0; i < this._tileCoordinator.positions.length; i++) {\n      const position = this._tileCoordinator.positions[i];\n      const {rowspan, colspan} = tiles[i];\n      // Return the tile harness if the given position visually resolves to the tile.\n      if (\n        column >= position.col &&\n        column <= position.col + colspan - 1 &&\n        row >= position.row &&\n        row <= position.row + rowspan - 1\n      ) {\n        return tileHarnesses[i];\n      }\n    }\n    throw Error('Could not find tile at given position.');\n  }\n}\n","sourceCodeStart":68,"sourceCodeEnd":89,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/grid-list/testing/grid-list-harness.ts#L68-L89","documentation":"MatGridListHarness.getTileAtPosition scans the rendered tile harnesses for one whose row/col span covers the requested position. When no tile occupies that cell it throws this error, since the harness API only returns existing tiles.","triggerScenarios":"Calling harness.getTileAtPosition({row: r, col: c}) during a test where no tile spans that cell — e.g. wrong coordinates for the layout, an off-by-one after a colspan/rowspan change, or querying a cell beyond the grid's cols rows.","commonSituations":"Test code written against an older tile layout; tiles rendered conditionally so the expected tile isn't in the DOM; miscounting because grid positions are zero-based while tests assumed one-based.","solutions":["Verify the row/col values are zero-based and match the actual tile placement (colspan/rowspan included).","Print or assert the full tile layout first with harness.getTiles() and inspect each tile's position before querying.","Ensure the tiles you expect are actually rendered (no *ngIf hiding them) before calling getTileAtPosition.","Catch the error in tests when the absence of a tile at a position is the expected assertion."],"exampleFix":"// before\nconst tile = await grid.getTileAtPosition({ row: 2, col: 3 });\n// after\nconst tiles = await grid.getTiles();\nconst tile = tiles.find(async t => (await t.getPosition()) .row === 2 && ...) // or guard:\nconst pos = { row: 2, col: 3 };\nlet tile;\ntry { tile = await grid.getTileAtPosition(pos); } catch { /* tile absent as expected */ }","handlingStrategy":"try-catch","validationCode":"const tiles = await grid.getTiles();\nconst positions = await Promise.all(tiles.map(t => t.getPosition()));\nconst exists = positions.some(p => pos.row >= p.row && pos.row < p.row + (p.rowspan ?? 1) && pos.col >= p.col && pos.col < p.col + (p.colspan ?? 1));\nif (!exists) return null; // skip lookup","typeGuard":null,"tryCatchPattern":"let tile: MatGridTileHarness | null = null;\ntry {\n  tile = await grid.getTileAtPosition({ row: 2, col: 3 });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Could not find tile')) {\n    tile = null; // expected absence in this test\n  } else { throw e; }\n}","preventionTips":["Remember grid positions are zero-based in harness APIs.","Assert the expected layout with getTiles() before positional lookups.","Update test coordinates whenever colspan/rowspan or cols change."],"tags":["angular-material","testing","component-harness","grid-list"],"backgroundTag":"element-not-found-at-position","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}