Cypress tests often become flaky when developers assume cy.wait('@alias') waits for every new request. It doesn’t. Aliases capture only the first match, so later waits may resolve instantly. The fix: re-intercept before each occurrence or use times: 1 to create one-shot intercepts that “consume” themselves. But the real solution is avoiding network waits altogether. Instead, rely on user-visible, accessible UI states (spinners, aria-busy, disabled buttons, status messages). This makes tests stable, realistic, and far more reliable than waiting on network events.Cypress tests often become flaky when developers assume cy.wait('@alias') waits for every new request. It doesn’t. Aliases capture only the first match, so later waits may resolve instantly. The fix: re-intercept before each occurrence or use times: 1 to create one-shot intercepts that “consume” themselves. But the real solution is avoiding network waits altogether. Instead, rely on user-visible, accessible UI states (spinners, aria-busy, disabled buttons, status messages). This makes tests stable, realistic, and far more reliable than waiting on network events.

Achieving Reliable E2E Tests in Cypress: Overcome cy.wait Pitfalls

2025/11/26 13:14

Cypress gives frontend engineers a superpower: the ability to write E2E tests that watch our app behave just like a real user would. But with great power comes… well, a lot of subtle flakiness if you’re not careful.

The cy.wait Illusion: What's Really Happening

The scenario is simple: you have a component that loads data, and after a user action, it loads new data using the same API endpoint. To ensure the new data has arrived, you intercept the request and then use cy.wait('@requestAlias') multiple times.

// A common, flawed approach: cy.intercept('GET', '/api/items/*', { fixture: 'item-1' }).as('getItems'); cy.visit('/items'); // 1. Wait for the initial load cy.wait('@getItems'); // ... User performs an action that triggers the SAME request ... // 2. Wait for the second load cy.wait('@getItems'); // <-- THIS IS THE PROBLEM

The Flaw

Cypress's cy.intercept logic is designed to capture a single match for an alias. When you call cy.wait('@getItems') for the first time, it finds the initial request, waits for its resolution, and then the alias is fulfilled.

When you call cy.wait('@getItems') a second time, Cypress does not reset the listener. Instead, it checks if a request has already been resolved with that alias. Because the first request has resolved, the second cy.wait command resolves immediately, without waiting for the new network call to finish. Your test is now racing against the network, not waiting for it.

Fix #1: Re-intercept before each expected request

(Works, explicit, but verbose)

cy.intercept('GET', '/api/items').as('getItems_1') cy.get('[data-testid=refresh]').click() cy.wait('@getItems_1') cy.intercept('GET', '/api/items').as('getItems_2') cy.get('[data-testid=load-more]').click() cy.wait('@getItems_2')

Clear, deterministic, but repetitive.

Fix #2: Use times: 1 to force Cypress to “consume” intercepts

(Cleaner: Cypress forgets the intercept after one match)

This is the missing tool many engineers don’t realize exists.

cy.intercept({ method: 'GET', pathname: '/api/items', times: 1 }).as('getItems') // trigger request 1 cy.get('[data-testid=refresh]').click() cy.wait('@getItems') cy.intercept({ method: 'GET', pathname: '/api/items', times: 1 }).as('getItems') // trigger request 2 cy.get('[data-testid=load-more]').click() cy.wait('@getItems')

Why this works:

  • times: 1 means Cypress removes the intercept after a single matching request
  • Re-declaring the intercept creates a fresh listener
  • Each cy.wait('@getItems') now truly waits for the next occurrence

This technique gives you explicit, occurrence-specific intercepts without alias clutter. For tests that must assert network behavior (payloads, headers, error flows), it’s a clean and robust pattern.

Fix #3: Stop waiting for requests altogether

(The best fix. UI > network.)

Here’s the golden rule:

That means the most stable tests assert what the user sees:

  • A loading spinner appears → disappears
  • A button becomes disabled → enabled
  • A success message appears when an action is complete.
  • The newly loaded element is now visible in the DOM.

Example with user-visible cues:

cy.get('[data-testid=refresh]').click() cy.get('[data-testid=spinner]').should('exist') cy.get('[data-testid=spinner]').should('not.exist') cy.get('[data-testid=item-list]') .children() .should('have.length.at.least', 1)

No reliance on internal network timing. No alias lifecycle. Zero flake.

Accessibility makes this even more robust

Accessible UI patterns make great Cypress hooks:

aria-busy attribute

<ul data-testid="item-list" aria-busy="true">

Test:

cy.get('[data-testid=item-list]').should('have.attr', 'aria-busy', 'false')

role="status" with live regions

<div role="status" aria-live="polite" data-testid="status"> Loading… </div>

Test:

cy.get('[data-testid=status]').should('contain', 'Loaded 10 items')

Disabled states for actions

cy.get('[data-testid=submit]').should('be.disabled') cy.get('[data-testid=submit]').should('not.be.disabled')

These patterns aid screen reader users and produce stable, deterministic E2E tests.

When waiting for requests is appropriate

There ARE valid scenarios:

  • Asserting payloads or query params
  • Mocking backend responses
  • Validating request ordering
  • Verifying retry logic
  • Testing error handling flows

For those cases: Combine times: 1 with explicit, fresh intercepts defined right before triggers.

For other cases: the test should rely on the UI state.

A combined real-world example

(Network + UI, the best of both worlds)

// UI-driven loading signal cy.get('[data-testid=create]').click() cy.get('[data-testid=spinner]').should('exist') // Network contract check cy.intercept({ method: 'POST', pathname: '/api/items', times: 1 }).as('postItem') cy.get('[data-testid=create]').click() cy.wait('@postItem') .its('request.body') .should('deep.include', { title: 'New item' }) // Final user-visible assertion cy.get('[data-testid=status]').should('contain', 'Item created')

The network part is accurate. The UI part is resilient. The test is rock-solid.

Final checklist

For accessible, deterministic, non-flaky Cypress tests

  • Prefer user-visible UI state, not network events
  • Use aria-busy, role="status", aria-live, and disabled states
  • When waiting for requests:
  • Re-intercept before each occurrence, OR
  • Use times: 1 to auto-expire the intercept
  • Avoid global, long-lived intercepts
  • Never assume cy.wait('@alias') waits “for the next request”
  • Make loading and completion states accessible (good for tests, good for users)

\

Disclaimer: The articles reposted on this site are sourced from public platforms and are provided for informational purposes only. They do not necessarily reflect the views of MEXC. All rights remain with the original authors. If you believe any content infringes on third-party rights, please contact [email protected] for removal. MEXC makes no guarantees regarding the accuracy, completeness, or timeliness of the content and is not responsible for any actions taken based on the information provided. The content does not constitute financial, legal, or other professional advice, nor should it be considered a recommendation or endorsement by MEXC.

You May Also Like

SEC urges caution on crypto wallets in latest investor guide

SEC urges caution on crypto wallets in latest investor guide

The SEC’s Office of Investor Education and Assistance issued a bulletin warning retail investors about crypto asset custody risks. The guidance covers how investors
Share
Crypto.news2025/12/15 01:45
Crucial Fed Rate Cut: October Probability Surges to 94%

Crucial Fed Rate Cut: October Probability Surges to 94%

BitcoinWorld Crucial Fed Rate Cut: October Probability Surges to 94% The financial world is buzzing with a significant development: the probability of a Fed rate cut in October has just seen a dramatic increase. This isn’t just a minor shift; it’s a monumental change that could ripple through global markets, including the dynamic cryptocurrency space. For anyone tracking economic indicators and their impact on investments, this update from the U.S. interest rate futures market is absolutely crucial. What Just Happened? Unpacking the FOMC Statement’s Impact Following the latest Federal Open Market Committee (FOMC) statement, market sentiment has decisively shifted. Before the announcement, the U.S. interest rate futures market had priced in a 71.6% chance of an October rate cut. However, after the statement, this figure surged to an astounding 94%. This jump indicates that traders and analysts are now overwhelmingly confident that the Federal Reserve will lower interest rates next month. Such a high probability suggests a strong consensus emerging from the Fed’s latest communications and economic outlook. A Fed rate cut typically means cheaper borrowing costs for businesses and consumers, which can stimulate economic activity. But what does this really signify for investors, especially those in the digital asset realm? Why is a Fed Rate Cut So Significant for Markets? When the Federal Reserve adjusts interest rates, it sends powerful signals across the entire financial ecosystem. A rate cut generally implies a more accommodative monetary policy, often enacted to boost economic growth or combat deflationary pressures. Impact on Traditional Markets: Stocks: Lower interest rates can make borrowing cheaper for companies, potentially boosting earnings and making stocks more attractive compared to bonds. Bonds: Existing bonds with higher yields might become more valuable, but new bonds will likely offer lower returns. Dollar Strength: A rate cut can weaken the U.S. dollar, making exports cheaper and potentially benefiting multinational corporations. Potential for Cryptocurrency Markets: The cryptocurrency market, while often seen as uncorrelated, can still react significantly to macro-economic shifts. A Fed rate cut could be interpreted as: Increased Risk Appetite: With traditional investments offering lower returns, investors might seek higher-yielding or more volatile assets like cryptocurrencies. Inflation Hedge Narrative: If rate cuts are perceived as a precursor to inflation, assets like Bitcoin, often dubbed “digital gold,” could gain traction as an inflation hedge. Liquidity Influx: A more accommodative monetary environment generally means more liquidity in the financial system, some of which could flow into digital assets. Looking Ahead: What Could This Mean for Your Portfolio? While the 94% probability for a Fed rate cut in October is compelling, it’s essential to consider the nuances. Market probabilities can shift, and the Fed’s ultimate decision will depend on incoming economic data. Actionable Insights: Stay Informed: Continue to monitor economic reports, inflation data, and future Fed statements. Diversify: A diversified portfolio can help mitigate risks associated with sudden market shifts. Assess Risk Tolerance: Understand how a potential rate cut might affect your specific investments and adjust your strategy accordingly. This increased likelihood of a Fed rate cut presents both opportunities and challenges. It underscores the interconnectedness of traditional finance and the emerging digital asset space. Investors should remain vigilant and prepared for potential volatility. The financial landscape is always evolving, and the significant surge in the probability of an October Fed rate cut is a clear signal of impending change. From stimulating economic growth to potentially fueling interest in digital assets, the implications are vast. Staying informed and strategically positioned will be key as we approach this crucial decision point. The market is now almost certain of a rate cut, and understanding its potential ripple effects is paramount for every investor. Frequently Asked Questions (FAQs) Q1: What is the Federal Open Market Committee (FOMC)? A1: The FOMC is the monetary policymaking body of the Federal Reserve System. It sets the federal funds rate, which influences other interest rates and economic conditions. Q2: How does a Fed rate cut impact the U.S. dollar? A2: A rate cut typically makes the U.S. dollar less attractive to foreign investors seeking higher returns, potentially leading to a weakening of the dollar against other currencies. Q3: Why might a Fed rate cut be good for cryptocurrency? A3: Lower interest rates can reduce the appeal of traditional investments, encouraging investors to seek higher returns in alternative assets like cryptocurrencies. It can also be seen as a sign of increased liquidity or potential inflation, benefiting assets like Bitcoin. Q4: Is a 94% probability a guarantee of a rate cut? A4: While a 94% probability is very high, it is not a guarantee. Market probabilities reflect current sentiment and data, but the Federal Reserve’s final decision will depend on all available economic information leading up to their meeting. Q5: What should investors do in response to this news? A5: Investors should stay informed about economic developments, review their portfolio diversification, and assess their risk tolerance. Consider how potential changes in interest rates might affect different asset classes and adjust strategies as needed. Did you find this analysis helpful? Share this article with your network to keep others informed about the potential impact of the upcoming Fed rate cut and its implications for the financial markets! To learn more about the latest crypto market trends, explore our article on key developments shaping Bitcoin price action. This post Crucial Fed Rate Cut: October Probability Surges to 94% first appeared on BitcoinWorld.
Share
Coinstats2025/09/18 02:25
Bitcoin’s Battle with Market Pressures Sparks Concerns

Bitcoin’s Battle with Market Pressures Sparks Concerns

Throughout the weekend, Bitcoin exhibited a degree of stability. Yet, it is once again challenging the critical support level of $88,000.Continue Reading:Bitcoin
Share
Coinstats2025/12/15 01:35