Skip to content

Instantly share code, notes, and snippets.

@jeffsaracco
Last active August 29, 2015 14:21
Show Gist options
  • Save jeffsaracco/fc82924cb5dbd171906b to your computer and use it in GitHub Desktop.
Save jeffsaracco/fc82924cb5dbd171906b to your computer and use it in GitHub Desktop.
Sinon synchronous tests with Q promises

The code below will effectively turn your Asynchronous Q promises synchronous so that they are easier to test.

  beforeEach(function () {
    sinon.stub(Q.xhr, 'post').returns(Q.resolve({myAwesome: 'response data goes here'}));
    sinon.stub(process, 'nextTick').yields();
  });

  afterEach(function () {
    Q.xhr.post.restore();
    process.nextTick.restore();
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment