The function:
async function functionUnderTest(isOK) {
if (isOK) return ' OK ' ;
throw new Error( ' not OK ' );
}
Behavior:
If isOK is true:
If isOK is false:
The function throws, which in an async function becomes a rejected promise with Error( ' not OK ' ).
We want an assertion that accurately tests the successful path for isOK === true.
Key points about console.assert:
Signature: console.assert(condition, message?)
If condition is falsy , it logs message as an assertion failure.
If condition is truthy , nothing is logged.
We also must understand await:
Now evaluate options.
Option A:
console.assert(await functionUnderTest(true), ' OK ' );
await functionUnderTest(true) → ' OK ' (truthy).
console.assert( ' OK ' , ' OK ' );
Condition is ' OK ' (truthy), so assertion passes.
The message ' OK ' is only shown if the condition is falsy, which it is not.
This correctly verifies that the promise resolved (i.e., did not reject). Among the given options, this is the only one that both:
Uses await properly on the async function, and
Associates the message with the expected success " OK " .
Option B:
console.assert(await (functionUnderTest(true), ' not OK ' ));
Inside the parentheses, the comma operator (a, b) evaluates a, discards it, and returns b.
So (functionUnderTest(true), ' not OK ' ):
Calls functionUnderTest(true) (returns a promise, but its result is discarded),
The expression evaluates to the string ' not OK ' .
Then await ' not OK ' just resolves to ' not OK ' immediately (not a promise).
console.assert( ' not OK ' );
Condition is ' not OK ' (truthy), so the assertion passes regardless of what functionUnderTest actually does.
This does not meaningfully test the function and is misleading.
Option C:
console.assert(functionUnderTest(true), ' OK ' );
functionUnderTest(true) returns a Promise , not the string ' OK ' directly.
A Promise object is always truthy.
So console.assert(promise, ' OK ' ) will pass, even if the promise later rejects.
Also, there is no await, so we are not actually waiting for the async result.
This is not a correct way to assert on an async function’s resolved value.
Option D:
console.assert(await functionUnderTest(true), ' not OK ' );
await functionUnderTest(true) still resolves to ' OK ' (truthy).
console.assert( ' OK ' , ' not OK ' ); passes.
However, the message ' not OK ' is the opposite of what we expect for the success case and is only used when the condition fails.
This makes the assertion logically inconsistent with the function behavior (it would show " not OK " if the assertion failed).
Therefore, the only assertion that:
Properly waits on the async function, and
Has expectation text that matches the successful behavior ( ' OK ' )
is:
Answer: A
Study Guide / Concept References (no links):
async and await behavior in JavaScript
Promises resolving vs rejecting in async functions
console.assert(condition, message) usage
Truthy and falsy values in JavaScript
Comma operator (a, b) semantics
Submit