From 7f1fb53c2c0d8567e1843f282b850a41632f5a25 Mon Sep 17 00:00:00 2001 From: Kyle Machulis Date: Sat, 20 Jan 2018 17:52:19 -0800 Subject: [PATCH] test: Add error tests for having too many vibrate subcommands --- tests/test-bluetoothdevices.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-bluetoothdevices.ts b/tests/test-bluetoothdevices.ts index d26320b6..b5ff46d5 100644 --- a/tests/test-bluetoothdevices.ts +++ b/tests/test-bluetoothdevices.ts @@ -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)); @@ -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]));