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', + }); + }); +});