Blog

Testing jQuery's AJAX "script" and "jsonp" requests using Sinon.JS' fake server

  • 25 January 2017
  • Programming

During writing tests for yii.js in Yii 2 framework I faced with problem of testing AJAX requests with types script and jsonp. I use Sinon.JS as a stubbing library, it has a wonderful feature called Fake server which comes in handy exactly for testing AJAX. Unfortunately there are some problems with these types:

  • Cross-domain requests do not work neither in Node nor in browser.
  • In Node.js they do not work at all, even the requests within the same site / domain.
  • #testing
  • #yii
  • #yii2
  • #javascript
  • #jquery
  • #ajax
  • #nodejs
  • #sinon
  • #chai
  • #mocha
Continue reading