title: Should I use wait() to wait for dialog to close? Is there a better way?
body: <p>I want to test that when I click a button that closes a modal dialog (ng material) that the modal does not exist.</p>
  
  <p><strong>This test actually closes the modal but it passes</strong></p>
  
  <pre><code>it('should close the modal when the close button is clicked', () =&gt; {
              cy.get('#close-new-category').click();
              cy.get('#new-category').should('exist');
  });
  </code></pre>
  
  <p><strong>This test works also</strong></p>
  
  <pre><code>it('should close the modal when the close button is clicked', () =&gt; {
              cy.get('#close-new-category').click();
              cy.get('#new-category').should('not.exist');
  });
  </code></pre>
  
  <p><strong>This test fails, if I add a wait</strong></p>
  
  <pre><code>it('should close the modal when the close button is clicked', () =&gt; {
                  cy.get('#close-new-category').click();
                  cy.wait(500);
                  cy.get('#new-category').should('exist');
  });
  </code></pre>
  
  <p><strong>This test passes as we should expect, but is using wait() the best way?</strong></p>
  
  <pre><code>it('should close the modal when the close button is clicked', () =&gt; {
              cy.get('#close-new-category').click();
              cy.wait(500);
              cy.get('#new-category').should('not.exist');
  });
  </code></pre>
  
  <p>I only ask because the documentation says this is an anti-pattern and there should be a better way.</p>