3

I use jquery-mockjax to mock my AJAX request for my tests and after I upgraded my ember from 2.3.0 -> 2.10.0 it no longer works because my service is using Ember.$.ajax() instead of directly $.ajax()

any idea how to make mockjax still work with Ember.$.ajax()? Or shall I just replace all Ember.$.ajax() instance to $.ajax()? Is this the only way?

GantengX
  • 1,471
  • 2
  • 16
  • 28
  • Replacing `Ember.$.ajax` by `$.ajax` is not good idea, because you will might get some problem in future - you will have to monitor ember changes. Why don't you use `ember-cli-mirage`? It's more convenient than `jquery-mockjax` and goes in footsteps `ember`. – ajile Dec 21 '16 at 08:05
  • 1
    Yeah because at work we already have a lot of mockup manually done using mockjax, switching to ember-cli-mirage will take a lot of time but I guess that's the only reasonable way :-/ – GantengX Dec 21 '16 at 08:40
  • I'm pretty sure [`Ember.$.ajax === $.ajax`](http://emberjs.com/api/#method__)! – Lux Dec 21 '16 at 21:33
  • it worked with ember 2.3 and 2.4 without any issue (calling `Ember.$.ajax` is actually mocked) – GantengX Dec 22 '16 at 01:59
  • Give [ember-cli-mirage](http://www.ember-cli-mirage.com/) a try. It's great addon to mock requests, works both with Ember.$.ajax() and ember data – Gennady Dogaev Dec 22 '16 at 09:51
  • What @Lux said... [Ember.$ is jQuery](https://github.com/emberjs/ember.js/blob/master/packages/ember/lib/index.js#L543), so I'm wondering if something else is going on. Can you open an issue in the [Mockjax repo](https://github.com/jakerella/jquery-mockjax/issues)? I can try to take a look this week. – Jordan Kasper Dec 24 '16 at 16:00
  • @jakerella my guess is in the newer Ember `Ember.$` doesn't point to the global jQuery instance hence mockjax doesn't work. I'm not sure which Ember version when it started to break though (I only know it doesn't work on 2.10 and I'm in the middle of upgrading to 2.4). I'll open an issue in a moment – GantengX Dec 27 '16 at 01:51
  • @jakerella I opened an issue in the mockjax repo - https://github.com/jakerella/jquery-mockjax/issues/308 – GantengX Dec 27 '16 at 02:56
  • I've updated the GH issue... I have a basic test in place for Ember 2.10.0 now and things seem to be working. I think this may be more about your specific use case. Be sure you are using the latest version of Mockjax! – Jordan Kasper Dec 28 '16 at 16:52
  • Thanks! I did use the latest version. I closed the GH issue for now, if I have this issue again I'll try to get more details and reopen it – GantengX Dec 29 '16 at 01:57

1 Answers1

1

Figured out the reason why mockjax didn't work (failed on Ember 2.9 -> 2.10 upgrade). I actually have additional jQuery dependency in my bower file and on ember-cli-build I actually imported jQuery. In Ember 2.10, reimporting jQuery somehow overrides the global instance, hence Ember.$ !== $ while in the previous versions it worked fine.

GantengX
  • 1,471
  • 2
  • 16
  • 28