Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(insights): await axis-title overlay in chart tests (#73823)

Thomas Obermüller4418f9f672f3
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx
index 87a69f9b6bca..f521794db5c0 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx
@@ -338,8 +338,12 @@ describe('SqlLineGraph', () => {
)
await screen.findByLabelText(/chart with/i)
- expect(getHogChart().xAxisLabel()).toBe(expectedX)
- expect(getHogChart().yAxisLabel()).toBe(expectedY)
+ // Axis titles are a layout-dependent overlay that commits a tick after the
+ // chart's aria-label appears, so read them through waitFor rather than synchronously.
+ await waitFor(() => {
+ expect(getHogChart().xAxisLabel()).toBe(expectedX)
+ expect(getHogChart().yAxisLabel()).toBe(expectedY)
+ })
})
})
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
index 4447a354a54c..1cf40a75f34a 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
@@ -231,13 +231,17 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
})
await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
- expect(getHogChart().xAxisLabel()).toBe('Total events')
- expect(getHogChart().yAxisLabel()).toBe('Series')
- expect(
- getHogChart()
- .element.querySelector<SVGTextElement>('[data-attr="hog-chart-axis-title-y"]')
- ?.getAttribute('transform')
- ).toContain('rotate(-90')
+ // Axis titles are a layout-dependent overlay that commits a tick after the
+ // chart's aria-label appears, so read them through waitFor rather than synchronously.
+ await waitFor(() => {
+ expect(getHogChart().xAxisLabel()).toBe('Total events')
+ expect(getHogChart().yAxisLabel()).toBe('Series')
+ expect(
+ getHogChart()
+ .element.querySelector<SVGTextElement>('[data-attr="hog-chart-axis-title-y"]')
+ ?.getAttribute('transform')
+ ).toContain('rotate(-90')
+ })
})
// Five hedgehog breakdowns → by default one series carrying five per-bar colors across five