Skip to content

Commit

Permalink
ble-pybricks-service/sagas: simplify test
Browse files Browse the repository at this point in the history
I meant to change this before merging the previous commit, but missed it.

The mismatch test was hard to understand and didn't increase coverage,
so let's leave it out.
  • Loading branch information
dlech committed Oct 27, 2024
1 parent 14f4716 commit 0472978
Showing 1 changed file with 8 additions and 40 deletions.
48 changes: 8 additions & 40 deletions src/ble-pybricks-service/sagas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,49 +232,17 @@ describe('event decoder', () => {
]).buffer,
),
],
[
'write appdata mismatch',
[
0x02, // write AppData event
't'.charCodeAt(0), //payload
'e'.charCodeAt(0),
't'.charCodeAt(0),
't'.charCodeAt(0),
],
didReceiveWriteAppData(
new Uint8Array([
't'.charCodeAt(0),
'e'.charCodeAt(0),
'x'.charCodeAt(0),
't'.charCodeAt(0),
]).buffer,
),
true,
false,
],
])(
'decode %s event',
async (_n, message, expected, isEqual = true, isStrictlyEqual = true) => {
const saga = new AsyncSaga(blePybricksService);
const notification = new Uint8Array(message);
])('decode %s event', async (_n, message, expected) => {
const saga = new AsyncSaga(blePybricksService);
const notification = new Uint8Array(message);

saga.put(didNotifyEvent(new DataView(notification.buffer)));
saga.put(didNotifyEvent(new DataView(notification.buffer)));

const action = await saga.take();
if (isEqual) {
expect(action).toEqual(expected);
} else {
expect(action).not.toEqual(expected);
}
if (isStrictlyEqual) {
expect(action).toStrictEqual(expected);
} else {
expect(action).not.toStrictEqual(expected);
}
const action = await saga.take();
expect(action).toEqual(expected);

await saga.end();
},
);
await saga.end();
});

test.each([
[
Expand Down

0 comments on commit 0472978

Please sign in to comment.