Cypress – Make assertions before letting the interception return the fixture

Situation

I am working on a page which has a form. When the button in the form is clicked, a request is sent to the backend and the page changes to show that it’s performing the operation (a progress bar appears, the background color changes, the button is disabled).
When the response arrives, the changes on the page are reverted and some fields are updated.

Now, I want to write a Cypress test that intercepts the call to the backend, checks that the button is disabled and all, then respond with a fixture before asserting that the fields have been updated. I know that I may set the delay field in the StaticResponse object of cy.intercept, but I am wondering if there is a way to do this that does not involve waiting for an arbitrary amount of time.

What I would want

I would like to be able to write something akin to this:

describe('Pseudocode', () => {
  it('could be nice', () => {
    cy.intercept('GET', '/printers', ['printer1']);
  
    // The 'wait' field would instruct intercept to wait for `cy.wait()` before returning
    const hypotheticalStaticResponse = { fixture: 'print-response-ok.json', wait: true };
    cy.intercept('POST', '/print', hypotheticalStaticResponse).as('printRequest');
  
    cy.visit('/form');
  
    cy.get('mat-form-field#box-identifier input').as('boxIdentifier');
    cy.get('div#print > button').as('printButton');
  
    cy.get('@boxIdentifier').type('1234567');
    // The call is made when the button is clicked
    cy.get('@printButton').click();
  
    cy.get('app-shipping-label').should('have.class', 'printing');
    cy.get('@printButton').should('be.disabled');
    cy.get('mat-progress-bar').should('be.visible');
  
    // The request would be answered only once we hit this instruction
    cy.wait('@printRequest');
  
    cy.get('app-shipping-label').should('have.class', 'ready');
    cy.get('mat-progress-bar').should('not.exist');
  });
}

What I tried

describe('Assertions on my form', () => {
  it("doesn't work without delay", () => {
    cy.intercept('GET', '/printers', ['printer1']);
  
    cy.intercept('POST', '/print', { fixture: 'print-response-ok.json' }).as('printRequest');
  
    cy.visit('/form');
  
    cy.get('div#print > button').as('printButton');
  
    cy.get('mat-form-field#box-identifier input').type('1234567');
    // The call is made when the button is clicked
    cy.get('@printButton').click();
  
    // Fails, because the fixture was already returned
    cy.get('app-shipping-label').should('have.class', 'printing');
    cy.get('@printButton').should('be.disabled');
    cy.get('mat-progress-bar').should('be.visible');
  
    cy.wait('@printRequest');
  
    cy.get('app-shipping-label').should('have.class', 'ready');
    cy.get('mat-progress-bar').should('not.exist');
  });
  
  it("doesn't work with inner gets", () => {
    cy.intercept('GET', '/printers', ['printer1']);
  
    cy.intercept('POST', '/print', { fixture: 'print-response-ok.json', delay: 500 }).as('printRequest');
  
    cy.visit('/form');
  
    cy.get('div#print > button').as('printButton');
  
    cy.get('mat-form-field#box-identifier input').type('1234567');
    // The call is made when the button is clicked
    cy.get('@printButton').click();
  
    cy.get('app-shipping-label').should('have.class', 'printing');
    cy.get('@printButton').should('be.disabled');
    cy.get('mat-progress-bar').should('be.visible');
  
    cy.wait('@printRequest').then(() => {
      // CypressError: `cy.then()` failed because you are mixing up async and sync code.
      cy.get('app-shipping-label').should('have.class', 'printing');
      cy.get('@printButton').should('be.disabled');
      cy.get('mat-progress-bar').should('be.visible');
    });
  
    cy.get('app-shipping-label').should('have.class', 'ready');
    cy.get('mat-progress-bar').should('not.exist');
  });
  
  it('works with a delay, but is there another way?', () => {
    cy.intercept('GET', '/printers', ['printer1']);
  
    cy.intercept('POST', '/print', { fixture: 'print-response-ok.json', delay: 500 }).as('printRequest');
  
    cy.visit('/form');
  
    cy.get('div#print > button').as('printButton');
  
    cy.get('mat-form-field#box-identifier input').type('1234567');
    // The call is made when the button is clicked
    cy.get('@printButton').click();
  
    cy.get('app-shipping-label').should('have.class', 'printing');
    cy.get('@printButton').should('be.disabled');
    cy.get('mat-progress-bar').should('be.visible');
  
    cy.wait('@printRequest');
  
    cy.get('app-shipping-label').should('have.class', 'ready');
    cy.get('mat-progress-bar').should('not.exist');
  });
};

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật