title: ember-cli-mirage testing request params
body: <p>I have default params that are added to the search request from a route. I would like to test these in ember-cli-mirage but am stuck on how to capture the request or requestBody so that I can assert against it.</p>
  
  <p>Was looking for something similar to what I found on <a href="https://stackoverflow.com/questions/32997349/testing-error-responses-with-ember-cli-mirage">this SO post</a>, but need access to the actual request and not the DOM. I am able to access the search params entered by the user (the 'text' param in my example) using currentUrl(), but the default params included in the request sent to the server, but not the url.</p>
  
  <p>Is there a way to capture and assert against the request itself using ember-cli-mirage?</p>
  
  <p>Something like</p>
  
  <pre><code>test('it appends default params to request'), function(assert) {
    let searchUrl = '/my/route/url';
  
    server.get(searchUrl, (db, request) =&gt; {
      assert.equal(request.requestBody, "text=abc&amp;all=true");
    }
  });
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I was able to get the test to pass using Qunit's async helper, like so:</p>
  
  <pre><code>test('it appends default params to athlete request', function(assert) {
    assert.expect(2);
    let done = assert.async();
  
    server.get('/athletes', (db, request) =&gt; {
      let params = request.queryParams;
      assert.equal(params["page"], "1");
      assert.equal(params["per"], "50");
      done();
    });
  
    server.create('athlete', {first_name: 'John'});
    visit('/athletes');
  });
  </code></pre>
  
  <p>Still getting an error in the console for this test related to the json:api serialization:</p>
  
  <pre><code>normalizeResponse must return a valid JSON API document:
          * meta must be an object
  </code></pre>
  
  <p>Going to open another question related to this failure elsewhere and link it in the comments.</p>