2

I'm having a frustrating time, and I'm not sure if it's Ember Mirage causing the problem or not. I have the following code in a service.

    Ember.$.get({
        url: `/api/online-courses/${Ember.get(course, 'id')}/courseData`,
        async: false, // use of deferreds, or promises, is deprecated with this setting
        beforeSend: function (xhr) {
          xhr.setRequestHeader('Authorization', Ember.get(service, 'ajax.headers')['Authorization'])
        },
        success: (result) => {
          globalState.initialized = true
          Ember.get(service, 'store').pushPayload('course-datum', result)
          initializeValues()
          returnVal = 'true'
        },
        error: (args) => {
          returnVal = 'false'
        }
      })

      return returnVal

I also have the route declared in my mirage/config.js file. It is set up to only use mirage during unit tests.

During the tests, I can follow the code execution through the XHR request, into the Mirage route handler, and then... nothing. It doesn't hit either of the success or error handlers defined in the Ember.$.get

When I execute this code in development against a real web-server, it works fine.

Does Mirage support the async:false flag? I also tried using this.pretender.get syntax to declare my end-point using the synchronous style defined here: https://github.com/pretenderjs/pretender#timing-parameter But still no joy...

Any ideas, nudges in the right direction, etc. would be hugely appreciated.

JonRed
  • 2,853
  • 5
  • 28
  • 37
  • If you do `async: true` does it work? Also, why is this request synchronous? – Sam Selikoff Mar 20 '16 at 12:42
  • Yeah, it works fine with async: true. It needs to be async because it's acting as an endpoint for a request that doesn't know, and can't be altered to know, about callbacks. The magic of implementing conformance to a 2001 spec. – JonRed Mar 20 '16 at 20:04
  • Next step would be to try a synchronous request against a "vanilla" Pretender server – Sam Selikoff Mar 21 '16 at 05:12

0 Answers0