From 6ef0dee20c7522c3561c070867689aa19b422d0d Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 21 May 2020 21:11:30 -0500 Subject: [PATCH] test utils/web-bluetooth --- src/utils/web-bluetooth.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/utils/web-bluetooth.test.ts diff --git a/src/utils/web-bluetooth.test.ts b/src/utils/web-bluetooth.test.ts new file mode 100644 index 00000000..62921123 --- /dev/null +++ b/src/utils/web-bluetooth.test.ts @@ -0,0 +1,26 @@ +import { polyfillBluetoothRemoteGATTCharacteristic } from './web-bluetooth'; + +describe('polyfillBluetoothRemoteGATTCharacteristic', () => { + test('old browser falls back to writeValue', () => { + const char = {} as BluetoothRemoteGATTCharacteristic; + Object.defineProperty(char, 'writeValue', { value: 'writeValue' }); + expect(polyfillBluetoothRemoteGATTCharacteristic(char)).toEqual({ + xWriteValueWithResponse: 'writeValue', + xWriteValueWithoutResponse: 'writeValue', + }); + }); + test('new browser uses writeValueWith(out)Response', () => { + const char = {} as BluetoothRemoteGATTCharacteristic; + Object.defineProperty(char, 'writeValue', { value: 'writeValue' }); + Object.defineProperty(char, 'writeValueWithResponse', { + value: 'writeValueWithResponse', + }); + Object.defineProperty(char, 'writeValueWithoutResponse', { + value: 'writeValueWithoutResponse', + }); + expect(polyfillBluetoothRemoteGATTCharacteristic(char)).toEqual({ + xWriteValueWithResponse: 'writeValueWithResponse', + xWriteValueWithoutResponse: 'writeValueWithoutResponse', + }); + }); +});