substantial / sinon-stub-promise

Synchronous Promise stubbing for Sinon.JS
MIT License
85 stars 11 forks source link

Synchronously call callbacks added to promise before resolves/rejects #18

Closed rhagigi closed 8 years ago

rhagigi commented 8 years ago

Useful when testing the state of something (for example dispatched actions to a flux store) before and after a promise is resolved (or rejected). Added unit tests too.

Simple example for resolved:

    var resolved = false;

    promise().then(function() {
      resolved = true;
    });

    expect(resolved).to.be.false;
    promise.resolves();
    expect(resolved).to.be.true;
a-b-r-o-w-n commented 8 years ago

Thanks for the contribution!

I am having a hard time seeing the benefit of this. Can you provide an example of testing a dispatched action?

rhagigi commented 8 years ago

Sure. Specifically I'm using this for optimistic updates. I call an action creator and expect that I've dispatched a "postingMessage" action prior to the server responding, and then after resolving or rejecting, expect that I've dispatched "messagePosted" or "messagePostError"

a-b-r-o-w-n commented 8 years ago

@amay would you mind taking a look at this one?

amay commented 8 years ago

Looks fine to me. Seems more compliant with how promises actually work.

amay commented 8 years ago

Going to bump to 3.0.0 because this would be a breaking change for anyone who relied on the old behavior.

amay commented 8 years ago

@astephenb looks like I don't have ownership of this package on npm so I can't publish. Can you do that when you have a second?

a-b-r-o-w-n commented 8 years ago

@amay AFAIK you can publish... try npm login and then try again?

@rhagigi I went ahead and published 3.0. Thanks for the contribution!

rhagigi commented 8 years ago

You didn't want to include the fix to allow chaining with withArgs and others? That one is a breaking change as well...

a-b-r-o-w-n commented 8 years ago

I think we can publish a new version with that change. Not sure if it's a major or minor version though. @rhagigi will you open a new PR with that work?