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
Stubs should have a resolves
and rejects
for setting promise results
#804
Comments
That would be some nice sugar, thank you for the suggestion @mariusGundersen |
Our team has a little library on npm which has been helping us with this kind of thing - https://github.com/substantial/sinon-stub-promise - although the way it's presently implemented it requires stub syntax like: |
I really like @mariusGundersen's suggestion. As far as I know, all promise libraries are async all the time, right? If so I think the stub promise should mirror this behavior. |
I just figured it would use the globally available var stub = sinon.stub();
stub.resolves("hello");
//is the same as
stub.returns({then: x => setTimeout(() => x("hello"), 0)});
stub.rejects(new Error("oh noes!"));
//is the same as
stub.returns({then: x => undefined, catch: x => setTimeout(() => x(new Error("oh noes!")), 0)}); (written on phone, might have errors) |
Our team wrote a little lib to provide similar functionality. Maybe this will help. It uses the bluebird library for promises. https://www.npmjs.com/package/sinon-bluebird |
+1 for native Promise support |
There's also a project called sinon-as-promised which patches your project's existing sinon module using native-promise-only to add resolves/rejects semantics to stubs. It'd be ace if this or the changes from one of the other modules could be added to sinon itself. |
Can I do a |
@jnystrom usage questions belong on the mailing list, but this is not something sinon currently supports as syntactic sugar. Perhaps you could suggest a syntax? Something like this should do what you want, and you don't need sinon for it.
|
Same from here: #738 |
Hello everyone, first of all, thanks for the excellent work you guys have been doing on Sinon. |
@lucasfcosta, thanks for that. I think @mroderick talked long ago about just integrating |
@lucasfcosta I would love to see a PR to integrate |
This is very simple syntax sugar:
The text was updated successfully, but these errors were encountered: