Skip to content

Commit

Permalink
test: Add error tests for having too many vibrate subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
qdot committed Jan 21, 2018
1 parent 27053ec commit 7f1fb53
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/test-bluetoothdevices.ts
Expand Up @@ -37,6 +37,8 @@ describe("WebBluetooth library tests", () => {
await bp.StartScanning();
await bp.StopScanning();
jest.spyOn(mockBT.txChar, "writeValue");
await expect(bp.SendDeviceMessage(bp.Devices[0], new VibrateCmd([new SpeedSubcommand(0, 1),
new SpeedSubcommand(0, 2)]))).rejects.toThrow();
await bp.SendDeviceMessage(bp.Devices[0], new VibrateCmd([new SpeedSubcommand(0, 1)]));
expect(mockBT.txChar.writeValue).toBeCalledWith(Buffer.from("Vibrate:20;"));
await bp.SendDeviceMessage(bp.Devices[0], new SingleMotorVibrateCmd(.5));
Expand All @@ -50,11 +52,9 @@ describe("WebBluetooth library tests", () => {
await bp.StartScanning();
await bp.StopScanning();
jest.spyOn(mockBT.txChar, "writeValue");
try {
await bp.SendDeviceMessage(bp.Devices[0], new VibrateCmd([new SpeedSubcommand(0, 1)]));
} catch (e) {
console.log(e);
}
await expect(bp.SendDeviceMessage(bp.Devices[0], new VibrateCmd([new SpeedSubcommand(0, 1),
new SpeedSubcommand(0, 2)]))).rejects.toThrow();
await bp.SendDeviceMessage(bp.Devices[0], new VibrateCmd([new SpeedSubcommand(0, 1)]));
expect(mockBT.txChar.writeValue).toBeCalledWith(new Uint8Array([0x0f, 0x03, 0x00, 0xff, 0x00, 0x03, 0x00, 0x00]));
await bp.SendDeviceMessage(bp.Devices[0], new SingleMotorVibrateCmd(.5));
expect(mockBT.txChar.writeValue).toBeCalledWith(new Uint8Array([0x0f, 0x03, 0x00, 0x77, 0x00, 0x03, 0x00, 0x00]));
Expand Down

0 comments on commit 7f1fb53

Please sign in to comment.