title: Custom Events and cy.get
body: <p>I need some help on how to handle the following situation. There is a modal that when closed sends an AJAX request, and if the response is successful a Datatables table is redrawn. I need to test the content of the table after the draw.dt event is fired. </p>
  
  <p>I get a reference to the table and then setup a handler for the draw.dt event. When the event fires cypress reports that cy.get cannot be run outside of a test. I suppose that the test is actually finished by the time this event gets processed.</p>
  
  <p>What is the correct way to handle this situation?</p>
  
  <pre><code>  cy.get('#commChannelModal &gt; .modal-dialog &gt; .modal-content &gt; .modal-footer &gt; .btn-primary')
              .contains(this.edit_controller_interface_data.modals.edit_comm_channel.buttons.save.text)
              .click({force: true}).then(function (){
  
                  cy.wait('@fetchComms').then(function () {
  
                      cy.get('#commChannelsTable').then(($table) =&gt; {
                          $table.on('draw.dt', function () {
                              // Verify in the index if the edited values are saved
                              cy.get('#commChannelsTable').get('tbody &gt; tr:nth-child(3) &gt; td:nth-child(1)')
                              .contains(this.edit_controller_interface_data.modals.edit_comm_channel.fields.connectionType.value)
  
                              cy.get('#commChannelsTable').get('tbody &gt; tr:nth-child(3) &gt; td:nth-child(2)')
                              .contains(this.edit_controller_interface_data.modals.edit_comm_channel.fields.ipAddress.value)
  
                              cy.get('#commChannelsTable').get('tbody &gt; tr:nth-child(3) &gt; td:nth-child(3)')
                              .contains(this.edit_controller_interface_data.modals.edit_comm_channel.fields.ipPort.value)
                          })
                      })
                  })
              })
  </code></pre>
  
  <p><a href="https://docs.cypress.io/guides/references/error-messages.html#Cypress-cannot-execute-commands-outside-a-running-test" rel="nofollow noreferrer">https://docs.cypress.io/guides/references/error-messages.html#Cypress-cannot-execute-commands-outside-a-running-test</a></p>