Recall & Review
beginner
What is the main challenge when testing asynchronous code?
The main challenge is ensuring the test waits for the async operation to complete before checking results, so tests don't finish too early and give false results.
Click to reveal answer
beginner
How do you tell a test framework like Jest to wait for an async function to finish?
You can return a Promise, use async/await syntax, or use a callback like 'done' to signal when the async work is complete.
Click to reveal answer
beginner
What does the 'async' keyword do in a test function?
It allows you to use 'await' inside the test, making the test wait for asynchronous code to finish before continuing.
Click to reveal answer
intermediate
Why should you avoid mixing callbacks and Promises in async tests?
Mixing them can cause confusion and errors, like tests finishing before async code runs, leading to unreliable test results.
Click to reveal answer
intermediate
How can you test that an async function throws an error?
Use 'await expect(asyncFunc()).rejects.toThrow()' in Jest to check that the Promise rejects with an error.
Click to reveal answer
Which keyword allows you to pause a test until an async operation completes?
✗ Incorrect
The 'await' keyword pauses the test until the Promise resolves or rejects.
In Jest, how do you signal that an async test using callbacks is finished?
✗ Incorrect
Calling 'done' tells Jest the async test is complete when using callbacks.
What happens if you forget to wait for an async function in a test?
✗ Incorrect
Without waiting, the test may finish before async code runs, causing wrong results.
Which Jest syntax checks that an async function throws an error?
✗ Incorrect
'rejects.toThrow()' is used to test rejected Promises with errors.
What is a good practice when writing async tests?
✗ Incorrect
Using async/await or returning Promises keeps tests clear and reliable.
Explain how to write a test for an asynchronous function using async/await in Node.js.
Think about how to pause the test until the async work finishes.
You got /4 concepts.
Describe how to test that an async function throws an error using Jest.
Focus on how Jest handles rejected Promises in tests.
You got /4 concepts.