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.

chore(taxonomic-filter): stabilize recent-selection value flow test (#91905)

posthog[bot]613b0a87afa4
diff --git a/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx b/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx
index 323a83117fe6..af657cb61ab1 100644
--- a/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx
+++ b/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx
@@ -92,16 +92,16 @@ describe('PropertyFilters recent selections', () => {
await userEvent.click(screen.getByTestId(tabTestId))
}
- // Typing here pays taxonomicFilterLogic's real 500ms search breakpoint (plus stacked 100ms
- // ones). Fake timers skip that wait; real timers resume immediately after so the resulting
- // MSW round trip settles normally instead of fighting fake-timer polling. setImmediate is
- // excluded like queueMicrotask (see jest.config.ts) — it also drives MSW v2's response pump.
- async function searchFor(query: string): Promise<void> {
+ // Every debounced input in this flow settles the same way: fake timers skip the wait, then
+ // real timers resume so the MSW round trip settles normally instead of fighting fake-timer
+ // polling. One strategy for the property search (taxonomicFilterLogic's 500ms breakpoint) and
+ // for the value load (propertyDefinitionsModel's 300ms breakpoint) keeps the test deterministic.
+ // setImmediate is excluded like queueMicrotask (see jest.config.ts) — it also drives MSW v2's
+ // response pump.
+ async function typeWithDebounce(field: HTMLElement, text: string): Promise<void> {
jest.useFakeTimers({ doNotFake: ['queueMicrotask', 'setImmediate'] })
try {
- await userEvent
- .setup({ advanceTimers: jest.advanceTimersByTime })
- .type(screen.getByTestId('taxonomic-filter-searchfield'), query)
+ await userEvent.setup({ advanceTimers: jest.advanceTimersByTime }).type(field, text)
await act(async () => {
jest.advanceTimersByTime(600)
})
@@ -110,6 +110,10 @@ describe('PropertyFilters recent selections', () => {
}
}
+ async function searchFor(query: string): Promise<void> {
+ await typeWithDebounce(screen.getByTestId('taxonomic-filter-searchfield'), query)
+ }
+
async function selectItem(itemTestId: string, onChange: jest.Mock): Promise<void> {
await userEvent.click(screen.getByTestId(itemTestId))
await waitFor(() => {
@@ -162,7 +166,7 @@ describe('PropertyFilters recent selections', () => {
})
const valueInput = await screen.findByPlaceholderText('Enter value...')
- await userEvent.type(valueInput, value)
+ await typeWithDebounce(valueInput, value)
await waitFor(() => {
expect(screen.getByTestId('prop-val-0')).toBeInTheDocument()
})