rufuspollock-okfn / recline.backend.gdocs

Javascript library for accessing Google Docs Spreadsheet - and also functions as a Recline backend!
14 stars 6 forks source link

Tests (Sinon) need to be made compatible with Ajax #13

Open KrishnaPG opened 9 years ago

KrishnaPG commented 9 years ago

Sinon test case is having difficulty with Ajax queries (such as JQuery.getJSON).

Died on test #1     at QUnit.test.global.test (http://okfnlabs.org/recline/test/sinon-qunit/1.0.0/sinon-qunit.js:60:16)
    at http://localhost:8000/Codebase/recline.backend.gdocs/test/backend.gdocs.test.js:275:1
    at http://localhost:8000/Codebase/recline.backend.gdocs/test/backend.gdocs.test.js:344:3: Cannot read property 'fail' of undefined
Source:     
TypeError: Cannot read property 'fail' of undefined
    at http://localhost:8000/Codebase/recline.backend.gdocs/backend.gdocs.js:33:10
    at Object.my.fetch (http://localhost:8000/Codebase/recline.backend.gdocs/backend.gdocs.js:36:6)
    at Object.<anonymous> (http://localhost:8000/Codebase/recline.backend.gdocs/test/backend.gdocs.test.js:292:25)
    at Object.sinon.test.config.injectIntoThis (http://okfnlabs.org/recline/test/sinon/1.7.1/sinon.js:3987:35)

Not a Sinon expert, but I think the explanation given here (http://stackoverflow.com/questions/12088029/how-to-spy-jquery-ajax-request) is applicable to this scenario

rufuspollock commented 9 years ago

Hmmm, this was working in 7c831c0c749c869f074d4e3e4831765f55e2eda9 - i.e. before merging your patches (my bad for not checking the merges better ;-0 ...). Could you take a quick look and see what fixes you need to make to get that test passing again with your new code (it may just be you need to stub the fail path or similar). If you have difficulties I can probably help.

KrishnaPG commented 9 years ago

Thank you Rufus.

I agree it was caused by my patch (for handling the failure results of ajax queries) - and infact I tried debugging and trying to fix it for about an hour before giving-up and posting here :)

For some reason this whole Sinon and ajax thing is elluding me (I am much of c / c++ guy trying to come terms with this javascript recently). I tried searching on the web about why this is happening and looks like they have some good reason (such as Sinon taking over the method prototype etc..) - shared the link in the my original post above - but couldn't figure how to actually resolve it.

In this case, I would have to ask for some experts help. Sorry for creating this situation - please help.

And my bad - in the past I created two patches (both now merged with main now) - tested one (which passed) and forgot to test the other one (which is creating problem now).

And BTW, the changes, however, are creating problem only with Sinon tests - because I have been using the changed code in production - and it never gave any problem.

rufuspollock commented 9 years ago

@KrishnaPG sinon stuff is just "mocking / stubbing" i.e. you replace the real function (e.g. $.ajax or $.getJSON) with a fake method that returns your test data (rather than having an actual call out). If you can, take a look at the code and see if you can figure it out.