Back to articles
Vitest's 4.1 New "Fast-Forward" Mode Skips Timer Delays Instantly

Vitest's 4.1 New "Fast-Forward" Mode Skips Timer Delays Instantly

via Dev.to WebdevYounes Jaaidi

An important property of tests is that they should be composable . Here is an example. Say you have a search component with a 300ms debounce. You've already tested the debounce behavior itself — "does it wait 300ms before firing?" — in a dedicated test. Now every other test that involves this component shouldn't care whether the debounce is there or not. Change the delay from 300ms to 500ms? Only the debounce test should break. Not the 15 other tests that just happen to type into that search field. Let's look at what this problem looks like, then at different approaches to solving it. The Challenge with Manual Fake Timers The classic approach of fake timers in manual mode breaks composability by coupling all the tests to the debounce. vi . useFakeTimers (); mountCookbookSearch (); await page . getByLabel ( ' Keywords ' ). fill ( ' Marmicode ' ); await vi . advanceTimersByTimeAsync ( 310 ); await expect . element ( page . getByRole ( ' heading ' )) . toHaveTextContent ( ' Angular Testin

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles