test utils/web-bluetooth

This commit is contained in:
David Lechner
2020-05-21 21:27:47 -05:00
committed by David Lechner
parent c979d21255
commit 6ef0dee20c
+26
View File
@@ -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',
});
});
});