-
Notifications
You must be signed in to change notification settings - Fork 14
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
Async detection through promises #14
Comments
A couple folks have asked about this. I wonder if it isn't a good opportunity for testing the extensibility of the teenytest API to allow plugins that augment runner behavior. I would somewhat slightly rather this be a plugin than built-in for two reasons:
|
Cc/ @schoon |
Ya, those are some interesting thoughts. I'd be interested to see an example of a test that incorrectly passes because a promise is no longer returned. That's not something I've run into before. I've definitely run into the confusion that comes from forgetting a return statement on a promise, but I've probably run into that confusion an equal number of times because I've either forgotten to add the With the final point about multiple chai-as-promised assertions being used in a single test, I ran into that too when I was first getting into promises. However, I don't think that's an issue with callbacks vs. promises as much as understanding what promises are and then properly structuring the tests. If multiple promises are going to be used in a single block, then by the nature of promises, they would need to be chained in order to work reliably. That chain can either be returned or you would have to add a final In my mind, the above gotchas are present either way. And in the course of practice, I find it more convenient to have the last line in a block return the promise rather than introduce and use a done callback. It kind of boils down to: let result
beforeEach(() => {
//arrange
return subject.doAsyncThing().then(r => result = r)
} vs. let result
beforeEach(done => {
//arrange
subject.doAsyncThing().then(r => result = r).then(done)
} |
And just to add some context, the reason I prefer the Also, I have code templates for all of these things, so it is more convenient to have a single template that will give me the skeleton for a block, and then if I need it to be async I just add the |
I still feel like I want this to be solved via a plugin that promisifies the callback API via a test transformer (this is an extension point hook I plan on implementing soon). By saying I want this to be a plugin doesn't mean I am dismissing your perspective as not valid, it means I want to divest this repo of as much as I can (the same would go for implementing a asideBy the way I was really hopeful that |
I think that sounds reasonable. |
Am I the schoon you are looking for? Not familiar with this repo. Thanks.
|
Whoops, sorry @schoon. I meant @Schoonology |
@josh-egan-ps ok this is shipped as of [email protected] and [email protected] |
I just stumbled across this repo and haven't played with it yet, but it looks pretty cool. One idea I had upon reading the README is that instead of requiring a callback parameter for async tests, performing promise detection would be a convenient way to also detect an async test. Perhaps using a package like is-promise
The text was updated successfully, but these errors were encountered: