question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor tests to return Promises when possible

See original GitHub issue

Throughout Ghost’s test suite there are many places where the done() async callback is used to handle asynchronous behavior. There are also many places where the test function returns a promise.

As part of #7165 the test cases that returned promises explicitly were refactored to not use the done() callback to handle behavior. (Mocha 3 throws an exception if you use both).

However, there are still lots of places throughout the tests that still use the done() callback because the test function doesn’t return a Promise when it should.

To close this issue, all of the tests cases need to be evaluated to see if they can return a Promise. If so, then they should be made to, and the done() callback should not be used in those instances.

Note: there still may be scenarios where the done callback needs to be used (for instance, if the test can’t return a promise) However, because most of the test functions that have asynchronous behavior do deal with promises, the need for explicitly using done should be very little

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Divya063commented, Oct 13, 2017

@ErisDS @kirrg001 Thank you so much for the information, I would like to work on #7696 as well as upgrading sinon/mocha.

1reaction
acburdinecommented, Jan 30, 2017

@janvt there’s already a PR open for this in #7254 - you might see if you can help out there 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asynchronous JavaScript: Refactoring Callbacks to Promises ...
This post demonstrates how to refactor an existing program which makes multiple API calls with traditional callbacks into a structure based on promise...
Read more >
Refactor commandAction to return a Promise #3430 - GitHub
Say we would refactor the commandAction function to return a Promise. ...we could then use async/await for all functions and directly await them...
Read more >
How can I unit test a function that uses promises and event ...
1) I tried spying on the Promise constructor so that it would return a fake function which would simply return a JSON string....
Read more >
JavaScript Promise Tutorial – How to Resolve or Reject ...
First, let us create a generic function that accepts a PokeAPI URL as argument and returns a Promise. If the API call is...
Read more >
Testing-library: avoid these mistakes in async tests
Never forget to await for async functions or return promises from the test (jest will wait for this promise to be resolved in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found