We use Jasmine for test-driven CoffeeScript. To unit test Ajax, we rely on jasmine-ajax to spy, mock and fake. A basic usage pattern is to jasmine.Ajax.useMock()
then check mostRecentAjaxRequest()
, but remember to clearAjaxRequests()
to avoid inconsistency (when running as part of a larger test suite).
Taking a look at the source, clearAjaxRequests()
is not called within the code. When running several tests are run in the same browser page, stale requests from previous tests may be returned by mostRecentAjaxRequest()
.
So, instead of jasmine.Ajax.useMock()
then check mostRecentAjaxRequest()
, adopt this pattern:
beforeEach ->
clearAjaxRequests()
...
afterEach ->
...
clearAjaxRequests()
it "should save the JSON data using Ajax", ->
jasmine.Ajax.useMock()
...
request = mostRecentAjaxRequest()
...
No comments:
Post a comment