DexterJS icon indicating copy to clipboard operation
DexterJS copied to clipboard

Add XHR2 callback support

Open spectras opened this issue 11 years ago • 5 comments

Hello,

I started using DexterJS for testing my ajax requests, and I really enjoy it so far. However, I am using JQuery 2 and I found out that the only callback supported in master is onreadystatechange. Unfortunately, JQuery2 wants to use onload and friends.

I quickly tweaked my local copy's __DexterStateChange to invoke onload when switching the state to DONE. That gets me going for now, but it is by no mean a clean solution. Proper support for the new callbacks would be awesome if someone fins the time to do it.

spectras avatar Jun 13 '14 21:06 spectras

:+1:

working on it, thanks

edit: For further reference: https://github.com/jquery/jquery/blob/master/src/ajax/xhr.js#L77-L110

leobalter avatar Jun 16 '14 02:06 leobalter

Great! By the way, you might be interested to know it works fine with Backbone. Here are some gotchas that might find their way into the documentation by the way:

  • I added fakeXHR.requests = [] to my QUnit module's setup to ensure my tests are independent. Otherwise, I might end up responding to requests from another testcase. If fakeXHR.requests is considered as an internal api, maybe it would be useful to add an accessor method?
  • I use requireJS:
    • I looked for fakeXHR for a while before I realized I had to add it as a requirement (define(['fakeXHR', 'dexter', ...] function (fakeXHR, dexter, ...) {).
    • to have fakeXHR work fine it needs a fakeXHR: "dexter" entry in the path configuration so it knows it is loaded from the same file as dexter.
    • apart from that, dexterjs plays surprinsingly well with requireJS.

spectras avatar Jun 16 '14 14:06 spectras

@luanmuniz help \o/

leobalter avatar Sep 05 '14 12:09 leobalter

working on it :)

luanmuniz avatar Sep 05 '14 17:09 luanmuniz

@raphamorim wanna try this challenge too? :)

leobalter avatar Sep 19 '14 02:09 leobalter