Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KrishnaPG opened this issue Jan 24, 2015 · 3 comments
Open

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

KrishnaPG opened this issue Jan 24, 2015 · 3 comments

Comments

@KrishnaPG
Copy link
Contributor

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
Copy link
Contributor

Hmmm, this was working in 7c831c0 - 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
Copy link
Contributor Author

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
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants