actions: simplify usage of Matchable

This removes use of the pseudo-internal toString() function and also
removes extraneous uses of ReturnType<>. Also, a new when() method
is added to simplify additional uses.
This commit is contained in:
David Lechner
2022-02-26 12:43:10 -06:00
parent 3cbfc4ca68
commit a9f4eaa32d
13 changed files with 125 additions and 142 deletions
+10 -6
View File
@@ -114,20 +114,24 @@ describe('message encoder', () => {
],
],
])('encode %s request', async (_n, request, expected) => {
const messageTypesThatShouldBeCalledWithoutResponse = [
eraseRequest.toString(),
programRequest.toString(),
rebootRequest.toString(),
disconnectRequest.toString(),
const requestsThatShouldBeCalledWithoutResponse = [
eraseRequest,
programRequest,
rebootRequest,
disconnectRequest,
];
const saga = new AsyncSaga(bootloader);
saga.put(request);
const message = new Uint8Array(expected);
const action = await saga.take();
expect(action).toEqual(
send(
message,
!messageTypesThatShouldBeCalledWithoutResponse.includes(request.type),
!requestsThatShouldBeCalledWithoutResponse.find((r) =>
r.matches(request),
),
),
);
await saga.end();
+2 -2
View File
@@ -116,8 +116,8 @@ function* encodeRequest(): Generator {
}
const { failedToSend } = yield* race({
sent: take<ReturnType<typeof didSend>>(didSend),
failedToSend: take<ReturnType<typeof didFailToSend>>(didFailToSend),
sent: take(didSend),
failedToSend: take(didFailToSend),
});
if (failedToSend) {