Add support to MockFeedback for promises
This change adds support for MockFeedback.prototype.replay() to be used in an async function. For example: async function test() { await doSomething(); await mockFeedback.expectSpeech('foo') .call(() => doSomethingElse) .replay(); } Alternatively, the following is similar, but bad usage: async function test() { await doSomething(); mockFeedback.expectSpeech('foo') .call(() => doSomethingElse) .replay(); } because the return statement is |undefined|. In CallbackHelper, test functions are only expected to return promises, and an async function that returns undefined automatically converts that value to a promise which automatically gets resolved. Such a promise passes the test incorrectly even if the test throws an assertion. THis occurs when MockFeedback which loops over all actions, gets an assertion, and does not hault execution and keeps trying to match expectations. If at some point, the expectation is matched in the future, the test passes. For existing tests that are not async, this change does not make any diffference. e.g. function test() { mockFeedback.call(() => doSomething) .expectSpeech('foo') .call(() => doSomethingElse) .replay(); } because CallbackHelper, when it receives no return value, goes back to the standard way of counting callbacks; when it hits zero, it finishes the test. The promise returned by replay doesn't make any impact on the test since the test is not async so returning undefined (implicitly here) does not convert it to a promise. AX-Relnotes: n/a Change-Id: I61509222a28730ee3bf8b80349bd11f4b9516636 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473805 Commit-Queue: David Tseng <dtseng@chromium.org> Reviewed-by:Dominic Mazzoni <dmazzoni@chromium.org> Cr-Commit-Position: refs/heads/master@{#818083}
Showing
Please register or sign in to comment