@stoprocent/noble 1.19.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +393 -650
  2. package/examples/advertisement-discovery.js +57 -48
  3. package/examples/connect-address.js +59 -34
  4. package/examples/echo.js +59 -69
  5. package/examples/enter-exit.js +55 -49
  6. package/examples/multiple-bindings.js +53 -0
  7. package/examples/peripheral-explorer-async.js +39 -21
  8. package/examples/peripheral-explorer.ts +52 -0
  9. package/index.d.ts +249 -209
  10. package/index.js +4 -1
  11. package/jest.config.js +4 -0
  12. package/lib/characteristic.js +153 -127
  13. package/lib/{win/src/callbacks.h → common/include/Emit.h} +17 -14
  14. package/lib/common/include/Peripheral.h +31 -0
  15. package/lib/common/include/ThreadSafeCallback.h +95 -0
  16. package/lib/{win/src/callbacks.cc → common/src/Emit.cc} +111 -68
  17. package/lib/descriptor.js +57 -54
  18. package/lib/hci-socket/acl-stream.js +2 -4
  19. package/lib/hci-socket/bindings.js +96 -73
  20. package/lib/hci-socket/gap.js +2 -3
  21. package/lib/hci-socket/gatt.js +2 -5
  22. package/lib/hci-socket/hci.js +19 -7
  23. package/lib/hci-socket/signaling.js +2 -3
  24. package/lib/hci-socket/smp.js +2 -3
  25. package/lib/hci-socket/vs.js +1 -0
  26. package/lib/mac/binding.gyp +5 -7
  27. package/lib/mac/bindings.js +1 -3
  28. package/lib/mac/src/ble_manager.h +1 -8
  29. package/lib/mac/src/ble_manager.mm +87 -44
  30. package/lib/mac/src/napi_objc.h +1 -0
  31. package/lib/mac/src/napi_objc.mm +0 -6
  32. package/lib/mac/src/noble_mac.h +5 -3
  33. package/lib/mac/src/noble_mac.mm +99 -57
  34. package/lib/mac/src/objc_cpp.h +3 -2
  35. package/lib/mac/src/objc_cpp.mm +0 -6
  36. package/lib/noble.js +579 -488
  37. package/lib/peripheral.js +171 -174
  38. package/lib/resolve-bindings.js +37 -30
  39. package/lib/service.js +58 -55
  40. package/lib/win/binding.gyp +4 -11
  41. package/lib/win/bindings.js +1 -3
  42. package/lib/win/src/ble_manager.cc +291 -166
  43. package/lib/win/src/ble_manager.h +11 -13
  44. package/lib/win/src/napi_winrt.cc +1 -7
  45. package/lib/win/src/napi_winrt.h +1 -1
  46. package/lib/win/src/noble_winrt.cc +88 -61
  47. package/lib/win/src/noble_winrt.h +5 -3
  48. package/lib/win/src/notify_map.cc +0 -7
  49. package/lib/win/src/notify_map.h +1 -8
  50. package/lib/win/src/peripheral_winrt.cc +29 -11
  51. package/lib/win/src/peripheral_winrt.h +1 -1
  52. package/lib/win/src/radio_watcher.cc +79 -69
  53. package/lib/win/src/radio_watcher.h +30 -11
  54. package/lib/win/src/winrt_cpp.cc +1 -1
  55. package/lib/win/src/winrt_cpp.h +3 -0
  56. package/package.json +14 -17
  57. package/prebuilds/darwin-x64+arm64/@stoprocent+noble.node +0 -0
  58. package/prebuilds/win32-ia32/@stoprocent+noble.node +0 -0
  59. package/prebuilds/win32-x64/@stoprocent+noble.node +0 -0
  60. package/test/lib/characteristic.test.js +202 -322
  61. package/test/lib/descriptor.test.js +62 -95
  62. package/test/lib/hci-socket/acl-stream.test.js +112 -108
  63. package/test/lib/hci-socket/bindings.test.js +576 -365
  64. package/test/lib/hci-socket/hci.test.js +442 -473
  65. package/test/lib/hci-socket/signaling.test.js +45 -48
  66. package/test/lib/hci-socket/smp.test.js +144 -142
  67. package/test/lib/hci-socket/vs.test.js +193 -18
  68. package/test/lib/peripheral.test.js +492 -322
  69. package/test/lib/resolve-bindings.test.js +207 -82
  70. package/test/lib/service.test.js +79 -88
  71. package/test/noble.test.js +381 -1085
  72. package/.editorconfig +0 -11
  73. package/.nycrc.json +0 -4
  74. package/codecov.yml +0 -5
  75. package/examples/cache-gatt-discovery.js +0 -198
  76. package/examples/cache-gatt-reconnect.js +0 -164
  77. package/examples/ext-advertisement-discovery.js +0 -65
  78. package/examples/peripheral-explorer.js +0 -225
  79. package/examples/pizza/central.js +0 -194
  80. package/examples/pizza/pizza.js +0 -60
  81. package/examples/test/test.custom.js +0 -131
  82. package/examples/uart-bind-params.js +0 -28
  83. package/lib/distributed/bindings.js +0 -326
  84. package/lib/mac/src/callbacks.cc +0 -222
  85. package/lib/mac/src/callbacks.h +0 -84
  86. package/lib/mac/src/peripheral.h +0 -23
  87. package/lib/resolve-bindings-web.js +0 -9
  88. package/lib/webbluetooth/bindings.js +0 -368
  89. package/lib/websocket/bindings.js +0 -321
  90. package/lib/win/src/peripheral.h +0 -23
  91. package/test/lib/distributed/bindings.test.js +0 -918
  92. package/test/lib/webbluetooth/bindings.test.js +0 -190
  93. package/test/lib/websocket/bindings.test.js +0 -456
  94. package/test/mocha.setup.js +0 -0
  95. package/with-bindings.js +0 -5
  96. package/with-custom-binding.js +0 -6
  97. package/ws-slave.js +0 -404
@@ -1,61 +1,122 @@
1
- const proxyquire = require('proxyquire').noCallThru();
2
1
  const should = require('should');
3
- const sinon = require('sinon');
4
- const { assert, fake } = sinon;
5
2
 
6
- describe('hci-socket bindings', () => {
7
- const AclStream = sinon.stub();
8
- const Gap = sinon.stub();
9
-
10
- const gattOnSpy = sinon.spy();
11
- const gattExchangeMtuSpy = sinon.spy();
12
- const Gatt = sinon.stub();
13
- Gatt.prototype.on = gattOnSpy;
14
- Gatt.prototype.exchangeMtu = gattExchangeMtuSpy;
15
-
16
- const createLeConnSpy = sinon.spy();
17
- const Hci = sinon.stub();
18
- Hci.prototype.createLeConn = createLeConnSpy;
19
- Hci.STATUS_MAPPER = { 1: 'custom mapper' };
20
-
21
- const signalingOnSpy = sinon.spy();
22
-
23
- const Signaling = sinon.stub();
24
- Signaling.prototype.on = signalingOnSpy;
25
-
26
- const Bindings = proxyquire('../../../lib/hci-socket/bindings', {
27
- './acl-stream': AclStream,
28
- './gap': Gap,
29
- './gatt': Gatt,
30
- './hci': Hci,
31
- './signaling': Signaling
32
- });
3
+ // Mock the required modules before importing the Bindings module
4
+ jest.mock('../../../lib/hci-socket/acl-stream', () => {
5
+ return jest.fn();
6
+ });
7
+
8
+ jest.mock('../../../lib/hci-socket/gap', () => {
9
+ const gapMock = jest.fn();
10
+ gapMock.prototype.on = jest.fn();
11
+ gapMock.prototype.setScanParameters = jest.fn().mockResolvedValue(null);
12
+ gapMock.prototype.startScanning = jest.fn().mockResolvedValue(null);
13
+ gapMock.prototype.stopScanning = jest.fn().mockResolvedValue(null);
14
+ gapMock.prototype.setAddress = jest.fn().mockResolvedValue(null);
15
+ gapMock.prototype.createLeConn = jest.fn().mockResolvedValue(null);
16
+ gapMock.prototype.disconnect = jest.fn().mockResolvedValue(null);
17
+ gapMock.prototype.reset = jest.fn().mockResolvedValue(null);
18
+ return gapMock;
19
+ });
20
+
21
+ jest.mock('../../../lib/hci-socket/gatt', () => {
22
+ const gattOnMock = jest.fn();
23
+ const gattExchangeMtuMock = jest.fn();
24
+
25
+ const gattMock = jest.fn().mockImplementation(() => ({
26
+ on: gattOnMock,
27
+ exchangeMtu: gattExchangeMtuMock
28
+ }));
29
+
30
+ // Make the mocks accessible for assertions
31
+ gattMock.onMock = gattOnMock;
32
+ gattMock.exchangeMtuMock = gattExchangeMtuMock;
33
+
34
+ return gattMock;
35
+ });
36
+
37
+ jest.mock('../../../lib/hci-socket/hci', () => {
38
+ const createLeConnSpy = jest.fn();
39
+
40
+ const hciMock = jest.fn();
41
+ hciMock.prototype.createLeConn = createLeConnSpy;
42
+ hciMock.prototype.on = jest.fn();
43
+ hciMock.prototype.init = jest.fn();
44
+ hciMock.prototype.setAddress = jest.fn().mockResolvedValue(null);
45
+ hciMock.prototype.reset = jest.fn().mockResolvedValue(null);
46
+
47
+ // Add STATUS_MAPPER to the constructor
48
+ hciMock.STATUS_MAPPER = { 1: 'custom mapper' };
49
+
50
+ // Make createLeConn accessible for later assertions
51
+ hciMock.createLeConnSpy = createLeConnSpy;
52
+
53
+ return hciMock;
54
+ });
55
+
56
+ jest.mock('../../../lib/hci-socket/signaling', () => {
57
+ const signalingOnMock = jest.fn();
58
+
59
+ const signalingMock = jest.fn().mockImplementation(() => ({
60
+ on: signalingOnMock
61
+ }));
62
+
63
+ // Make the mock accessible for assertions
64
+ signalingMock.onMock = signalingOnMock;
65
+
66
+ return signalingMock;
67
+ });
68
+
69
+ // Mock 'os' module
70
+ jest.mock('os', () => ({
71
+ platform: jest.fn().mockReturnValue('linux')
72
+ }));
73
+
74
+ // Import the Bindings module after mocking
75
+ const Bindings = require('../../../lib/hci-socket/bindings');
76
+ const Gap = require('../../../lib/hci-socket/gap');
77
+ const Gatt = require('../../../lib/hci-socket/gatt');
78
+ const Hci = require('../../../lib/hci-socket/hci');
79
+ const AclStream = require('../../../lib/hci-socket/acl-stream');
80
+ const Signaling = require('../../../lib/hci-socket/signaling');
33
81
 
82
+ describe('hci-socket bindings', () => {
34
83
  let bindings;
35
- let clock;
36
84
  const options = {};
37
-
85
+
38
86
  beforeEach(() => {
39
- sinon.stub(process, 'on');
40
- sinon.stub(process, 'exit');
41
-
87
+ // Mock process methods
88
+ jest.spyOn(process, 'on').mockImplementation(() => {});
89
+ jest.spyOn(process, 'exit').mockImplementation(() => {});
90
+
91
+ // Mock console.warn - silent implementation
92
+ jest.spyOn(console, 'warn').mockImplementation(() => {});
93
+
94
+ // Reset all mock state
95
+ jest.clearAllMocks();
96
+
97
+ // Mock timing functions
98
+ jest.useFakeTimers();
99
+
100
+ // Create bindings instance and start it
42
101
  bindings = new Bindings(options);
43
- clock = sinon.useFakeTimers();
102
+ bindings.start();
44
103
  });
45
104
 
46
105
  afterEach(() => {
47
- process.on.restore();
48
- process.exit.restore();
49
- clock.restore();
50
- sinon.reset();
106
+ jest.useRealTimers();
107
+ jest.restoreAllMocks(); // This will restore both process and console.warn mocks
51
108
  });
52
109
 
53
110
  it('constructor', () => {
54
111
  should(bindings._state).eql(null);
112
+ should(bindings._isScanning).eql(false);
113
+ should(bindings._isScanningStarted).eql(false);
55
114
 
56
115
  should(bindings._addresses).deepEqual({});
57
116
  should(bindings._addresseTypes).deepEqual({});
58
117
  should(bindings._connectable).deepEqual({});
118
+ should(bindings._isExtended).eql('extended' in options && options.extended);
119
+ should(bindings.scannable).deepEqual({});
59
120
 
60
121
  should(bindings._pendingConnectionUuid).eql(null);
61
122
  should(bindings._connectionQueue).deepEqual([]);
@@ -65,14 +126,14 @@ describe('hci-socket bindings', () => {
65
126
  should(bindings._aclStreams).deepEqual({});
66
127
  should(bindings._signalings).deepEqual({});
67
128
 
68
- should(bindings._hci).instanceOf(Hci);
69
- should(bindings._gap).instanceOf(Gap);
129
+ });
70
130
 
71
- assert.calledOnce(Hci);
72
- assert.calledWith(Hci, options);
131
+ it('start', () => {
132
+ expect(bindings._gap.on).toHaveBeenCalledTimes(4);
133
+ expect(bindings._hci.on).toHaveBeenCalledTimes(8);
134
+ expect(bindings._hci.init).toHaveBeenCalledTimes(1);
73
135
 
74
- assert.calledOnce(Gap);
75
- assert.calledWith(Gap, bindings._hci);
136
+ expect(process.on).toHaveBeenCalledTimes(2);
76
137
  });
77
138
 
78
139
  describe('onSigInt', () => {
@@ -80,60 +141,96 @@ describe('hci-socket bindings', () => {
80
141
  const sigIntListeners = process.listeners('SIGINT');
81
142
  bindings._sigIntHandler = sigIntListeners[sigIntListeners.length - 1];
82
143
  bindings.onSigInt();
83
- assert.calledOnceWithExactly(process.exit, 1);
144
+ expect(process.exit).toHaveBeenCalledWith(1);
145
+ expect(process.exit).toHaveBeenCalledTimes(1);
84
146
  });
85
147
 
86
148
  it('should not exit', () => {
87
- bindings._sigIntHandler = sinon.spy();
149
+ bindings._sigIntHandler = jest.fn();
88
150
  bindings.onSigInt();
89
- assert.notCalled(process.exit);
151
+ expect(process.exit).not.toHaveBeenCalled();
90
152
  });
91
153
  });
92
154
 
93
155
  it('setScanParameters', () => {
94
- bindings._gap.setScanParameters = fake.resolves(null);
95
-
96
156
  bindings.setScanParameters('interval', 'window');
97
157
 
98
- assert.calledOnce(bindings._gap.setScanParameters);
99
- assert.calledWith(bindings._gap.setScanParameters, 'interval', 'window');
158
+ expect(bindings._gap.setScanParameters).toHaveBeenCalledTimes(1);
159
+ expect(bindings._gap.setScanParameters).toHaveBeenCalledWith('interval', 'window');
100
160
  });
101
161
 
102
162
  describe('startScanning', () => {
103
- it('no args', () => {
104
- bindings._gap.startScanning = fake.resolves(null);
163
+ it('no args, already scanning', () => {
164
+ bindings._isScanning = true;
165
+ const scanStartSpy = jest.fn();
166
+ bindings.on('scanStart', scanStartSpy);
105
167
 
106
168
  bindings.startScanning();
107
169
 
108
170
  should(bindings._scanServiceUuids).deepEqual([]);
171
+ expect(scanStartSpy).toHaveBeenCalledTimes(1);
172
+ expect(bindings._gap.startScanning).not.toHaveBeenCalled();
173
+ });
174
+
175
+ it('no args, not scanning but started', () => {
176
+ bindings._isScanning = false;
177
+ bindings._isScanningStarted = true;
178
+ bindings._gap.startScanning = jest.fn();
109
179
 
110
- assert.calledOnce(bindings._gap.startScanning);
111
- assert.calledWith(bindings._gap.startScanning, undefined);
180
+ bindings.startScanning();
181
+
182
+ should(bindings._scanServiceUuids).deepEqual([]);
183
+ expect(bindings._gap.startScanning).not.toHaveBeenCalled();
112
184
  });
113
185
 
114
- it('with args', () => {
115
- bindings._gap.startScanning = fake.resolves(null);
186
+ it('with args, first time', () => {
187
+ bindings._isScanning = false;
188
+ bindings._isScanningStarted = false;
189
+ bindings._gap.startScanning = jest.fn();
116
190
 
117
191
  bindings.startScanning(['uuid'], true);
118
192
 
119
193
  should(bindings._scanServiceUuids).deepEqual(['uuid']);
194
+ should(bindings._isScanningStarted).true();
120
195
 
121
- assert.calledOnce(bindings._gap.startScanning);
122
- assert.calledWith(bindings._gap.startScanning, true);
196
+ expect(bindings._gap.startScanning).toHaveBeenCalledTimes(1);
197
+ expect(bindings._gap.startScanning).toHaveBeenCalledWith(true);
123
198
  });
124
199
  });
125
200
 
126
- it('stopScanning', () => {
127
- bindings._gap.stopScanning = fake.resolves(null);
201
+ describe('stopScanning', () => {
202
+ it('when scanning', () => {
203
+ bindings._isScanning = true;
204
+ bindings._gap.stopScanning = jest.fn();
205
+
206
+ bindings.stopScanning();
207
+
208
+ expect(bindings._gap.stopScanning).toHaveBeenCalledTimes(1);
209
+ });
210
+
211
+ it('when not scanning', () => {
212
+ bindings._isScanning = false;
213
+ bindings._gap.stopScanning = jest.fn();
214
+ const scanStopSpy = jest.fn();
215
+ bindings.on('scanStop', scanStopSpy);
216
+
217
+ bindings.stopScanning();
218
+
219
+ expect(bindings._gap.stopScanning).not.toHaveBeenCalled();
220
+ expect(scanStopSpy).toHaveBeenCalledTimes(1);
221
+ });
222
+ });
128
223
 
129
- bindings.stopScanning();
224
+ it('setAddress', () => {
225
+ bindings.setAddress('test-address');
130
226
 
131
- assert.calledOnce(bindings._gap.stopScanning);
227
+ expect(bindings._hci.setAddress).toHaveBeenCalledTimes(1);
228
+ expect(bindings._hci.setAddress).toHaveBeenCalledWith('test-address');
132
229
  });
133
230
 
134
231
  describe('connect', () => {
135
232
  it('missing peripheral, no queue, public address', () => {
136
- bindings._hci.createLeConn = fake.resolves(null);
233
+ bindings._hci.createLeConn = jest.fn();
137
234
 
138
235
  bindings.connect('112233445566', { addressType: 'public' });
139
236
 
@@ -141,12 +238,12 @@ describe('hci-socket bindings', () => {
141
238
  should(bindings._connectionQueue[0].id).eql('112233445566');
142
239
  should(bindings._connectionQueue[0].params).eql({ addressType: 'public' });
143
240
 
144
- assert.calledOnce(bindings._hci.createLeConn);
145
- assert.calledWith(bindings._hci.createLeConn, '11:22:33:44:55:66', 'public', { addressType: 'public' });
241
+ expect(bindings._hci.createLeConn).toHaveBeenCalledTimes(1);
242
+ expect(bindings._hci.createLeConn).toHaveBeenCalledWith('11:22:33:44:55:66', 'public', { addressType: 'public' });
146
243
  });
147
244
 
148
245
  it('missing peripheral, no queue, random address', () => {
149
- bindings._hci.createLeConn = fake.resolves(null);
246
+ bindings._hci.createLeConn = jest.fn();
150
247
 
151
248
  bindings.connect('f32233445566', { addressType: 'random' });
152
249
 
@@ -154,12 +251,12 @@ describe('hci-socket bindings', () => {
154
251
  should(bindings._connectionQueue[0].id).eql('f32233445566');
155
252
  should(bindings._connectionQueue[0].params).eql({ addressType: 'random' });
156
253
 
157
- assert.calledOnce(bindings._hci.createLeConn);
158
- assert.calledWith(bindings._hci.createLeConn, 'f3:22:33:44:55:66', 'random', { addressType: 'random' });
254
+ expect(bindings._hci.createLeConn).toHaveBeenCalledTimes(1);
255
+ expect(bindings._hci.createLeConn).toHaveBeenCalledWith('f3:22:33:44:55:66', 'random', { addressType: 'random' });
159
256
  });
160
257
 
161
258
  it('existing peripheral, no queue', () => {
162
- bindings._hci.createLeConn = fake.resolves(null);
259
+ bindings._hci.createLeConn = jest.fn();
163
260
  bindings._addresses = {
164
261
  peripheralUuid: 'address'
165
262
  };
@@ -173,8 +270,8 @@ describe('hci-socket bindings', () => {
173
270
  should(bindings._connectionQueue[0].id).eql('peripheralUuid');
174
271
  should(bindings._connectionQueue[0].params).eql('parameters');
175
272
 
176
- assert.calledOnce(bindings._hci.createLeConn);
177
- assert.calledWith(bindings._hci.createLeConn, 'address', 'addressType', 'parameters');
273
+ expect(bindings._hci.createLeConn).toHaveBeenCalledTimes(1);
274
+ expect(bindings._hci.createLeConn).toHaveBeenCalledWith('address', 'addressType', 'parameters');
178
275
  });
179
276
 
180
277
  it('missing peripheral, with queue', () => {
@@ -190,24 +287,24 @@ describe('hci-socket bindings', () => {
190
287
 
191
288
  describe('disconnect', () => {
192
289
  it('missing handle', () => {
193
- bindings._hci.disconnect = fake.resolves(null);
290
+ bindings._hci.disconnect = jest.fn();
194
291
 
195
292
  bindings.disconnect('peripheralUuid');
196
293
 
197
- assert.calledOnce(bindings._hci.disconnect);
198
- assert.calledWith(bindings._hci.disconnect, undefined);
294
+ expect(bindings._hci.disconnect).toHaveBeenCalledTimes(1);
295
+ expect(bindings._hci.disconnect).toHaveBeenCalledWith(undefined);
199
296
  });
200
297
 
201
298
  it('existing handle', () => {
202
299
  bindings._handles = {
203
300
  peripheralUuid: 'handle'
204
301
  };
205
- bindings._hci.disconnect = fake.resolves(null);
302
+ bindings._hci.disconnect = jest.fn();
206
303
 
207
304
  bindings.disconnect('peripheralUuid');
208
305
 
209
- assert.calledOnce(bindings._hci.disconnect);
210
- assert.calledWith(bindings._hci.disconnect, 'handle');
306
+ expect(bindings._hci.disconnect).toHaveBeenCalledTimes(1);
307
+ expect(bindings._hci.disconnect).toHaveBeenCalledWith('handle');
211
308
  });
212
309
  });
213
310
 
@@ -215,14 +312,14 @@ describe('hci-socket bindings', () => {
215
312
  it('missing handle', () => {
216
313
  bindings._connectionQueue.push({ id: 'anotherPeripheralUuid' });
217
314
 
218
- bindings._hci.cancelConnect = fake.resolves(null);
315
+ bindings._hci.cancelConnect = jest.fn();
219
316
 
220
317
  bindings.cancelConnect('peripheralUuid');
221
318
 
222
319
  should(bindings._connectionQueue).size(1);
223
320
 
224
- assert.calledOnce(bindings._hci.cancelConnect);
225
- assert.calledWith(bindings._hci.cancelConnect, undefined);
321
+ expect(bindings._hci.cancelConnect).toHaveBeenCalledTimes(1);
322
+ expect(bindings._hci.cancelConnect).toHaveBeenCalledWith(undefined);
226
323
  });
227
324
 
228
325
  it('existing handle', () => {
@@ -231,188 +328,177 @@ describe('hci-socket bindings', () => {
231
328
  };
232
329
  bindings._connectionQueue.push({ id: 'anotherPeripheralUuid' });
233
330
  bindings._connectionQueue.push({ id: 'peripheralUuid' });
234
- bindings._hci.cancelConnect = fake.resolves(null);
331
+ bindings._hci.cancelConnect = jest.fn();
235
332
 
236
333
  bindings.cancelConnect('peripheralUuid');
237
334
 
238
335
  should(bindings._connectionQueue).size(1);
239
336
 
240
- assert.calledOnce(bindings._hci.cancelConnect);
241
- assert.calledWith(bindings._hci.cancelConnect, 'handle');
337
+ expect(bindings._hci.cancelConnect).toHaveBeenCalledTimes(1);
338
+ expect(bindings._hci.cancelConnect).toHaveBeenCalledWith('handle');
242
339
  });
243
340
  });
244
341
 
245
- it('reset', () => {
246
- bindings._hci.reset = fake.resolves(null);
247
-
248
- bindings.reset();
249
-
250
- assert.calledOnce(bindings._hci.reset);
251
- });
252
-
253
342
  describe('updateRssi', () => {
254
343
  it('missing handle', () => {
255
- bindings._hci.readRssi = fake.resolves(null);
344
+ bindings._hci.readRssi = jest.fn();
256
345
 
257
346
  bindings.updateRssi('peripheralUuid');
258
347
 
259
- assert.calledOnce(bindings._hci.readRssi);
260
- assert.calledWith(bindings._hci.readRssi, undefined);
348
+ expect(bindings._hci.readRssi).toHaveBeenCalledTimes(1);
349
+ expect(bindings._hci.readRssi).toHaveBeenCalledWith(undefined);
261
350
  });
262
351
 
263
352
  it('existing handle', () => {
264
353
  bindings._handles = {
265
354
  peripheralUuid: 'handle'
266
355
  };
267
- bindings._hci.readRssi = fake.resolves(null);
356
+ bindings._hci.readRssi = jest.fn();
268
357
 
269
358
  bindings.updateRssi('peripheralUuid');
270
359
 
271
- assert.calledOnce(bindings._hci.readRssi);
272
- assert.calledWith(bindings._hci.readRssi, 'handle');
360
+ expect(bindings._hci.readRssi).toHaveBeenCalledTimes(1);
361
+ expect(bindings._hci.readRssi).toHaveBeenCalledWith('handle');
273
362
  });
274
363
  });
275
364
 
276
- it('init', () => {
277
- bindings._gap.on = fake.resolves(null);
278
- bindings._hci.on = fake.resolves(null);
279
- bindings._hci.init = fake.resolves(null);
280
-
281
- bindings.init();
282
-
283
- assert.callCount(bindings._gap.on, 4);
284
- assert.callCount(bindings._hci.on, 8);
285
- assert.calledOnce(bindings._hci.init);
286
-
287
- assert.calledTwice(process.on);
288
- });
289
-
290
365
  describe('stop', () => {
291
366
  it('no handles', () => {
292
- bindings._gap.stopScanning = fake.resolves(null);
293
- bindings._hci.reset = fake.resolves(null);
294
- bindings._hci.stop = fake.resolves(null);
295
- bindings._sigIntHandler = fake.resolves(null);
296
- bindings._exitHandler = fake.resolves(null);
367
+ bindings._isScanning = true;
368
+ bindings._gap.stopScanning = jest.fn();
369
+ bindings._hci.reset = jest.fn();
370
+ bindings._hci.stop = jest.fn();
371
+ bindings._sigIntHandler = jest.fn();
372
+ bindings._exitHandler = jest.fn();
297
373
 
298
374
  bindings.stop();
299
-
300
- assert.calledOnce(bindings._gap.stopScanning);
301
- assert.calledOnce(bindings._hci.reset);
302
- assert.calledOnce(bindings._hci.stop);
375
+
376
+ expect(bindings._gap.stopScanning).toHaveBeenCalledTimes(1);
377
+ expect(bindings._hci.reset).not.toHaveBeenCalled(); // Reset is not called in stop()
378
+ expect(bindings._hci.stop).toHaveBeenCalledTimes(1);
303
379
  });
304
380
 
305
381
  it('with handles', () => {
306
- bindings._gap.stopScanning = fake.resolves(null);
307
- bindings._hci.disconnect = fake.resolves(null);
308
- bindings._hci.reset = fake.resolves(null);
309
- bindings._hci.stop = fake.resolves(null);
310
- bindings._sigIntHandler = fake.resolves(null);
311
- bindings._exitHandler = fake.resolves(null);
382
+ bindings._isScanning = true;
383
+ bindings._gap.stopScanning = jest.fn();
384
+ bindings._hci.disconnect = jest.fn();
385
+ bindings._hci.reset = jest.fn();
386
+ bindings._hci.stop = jest.fn();
387
+ bindings._sigIntHandler = jest.fn();
388
+ bindings._exitHandler = jest.fn();
312
389
 
313
390
  bindings._aclStreams = [1, 2, 3];
314
391
 
315
392
  bindings.stop();
316
393
 
317
- assert.calledOnce(bindings._gap.stopScanning);
318
- assert.calledThrice(bindings._hci.disconnect);
394
+ expect(bindings._gap.stopScanning).toHaveBeenCalledTimes(1);
395
+ expect(bindings._hci.disconnect).toHaveBeenCalledTimes(3);
319
396
  });
320
397
  });
321
398
 
322
399
  describe('onStateChange', () => {
323
400
  it('same state', () => {
324
- const stateChange = fake.resolves(null);
401
+ const stateChange = jest.fn();
325
402
 
326
403
  bindings._state = 'state';
327
404
  bindings.on('stateChange', stateChange);
328
405
 
329
406
  bindings.onStateChange('state');
330
407
 
331
- assert.notCalled(stateChange);
408
+ expect(stateChange).not.toHaveBeenCalled();
332
409
  });
333
410
 
334
411
  it('new state', () => {
335
- const stateChange = fake.resolves(null);
412
+ const stateChange = jest.fn();
336
413
 
337
414
  bindings._state = 'state';
338
415
  bindings.on('stateChange', stateChange);
339
416
 
340
417
  bindings.onStateChange('newState');
341
418
 
342
- assert.calledOnce(stateChange);
343
- assert.calledWith(stateChange, 'newState');
419
+ expect(stateChange).toHaveBeenCalledTimes(1);
420
+ expect(stateChange).toHaveBeenCalledWith('newState');
344
421
  });
345
422
 
346
423
  it('unauthorized', () => {
347
- const stateChange = fake.resolves(null);
424
+ const stateChange = jest.fn();
348
425
 
349
426
  bindings._state = 'state';
350
427
  bindings.on('stateChange', stateChange);
428
+
429
+ jest.spyOn(console, 'log').mockImplementation(() => {});
351
430
 
352
431
  bindings.onStateChange('unauthorized');
353
432
 
354
- assert.calledOnce(stateChange);
355
- assert.calledWith(stateChange, 'unauthorized');
433
+ expect(stateChange).toHaveBeenCalledTimes(1);
434
+ expect(stateChange).toHaveBeenCalledWith('unauthorized');
435
+
436
+ expect(console.log).toHaveBeenCalledTimes(3);
437
+ expect(console.log).toHaveBeenCalledWith(expect.stringContaining('adapter state unauthorized'));
356
438
  });
357
439
 
358
440
  it('unsupported', () => {
359
- const stateChange = fake.resolves(null);
441
+ const stateChange = jest.fn();
360
442
 
361
443
  bindings._state = 'state';
362
444
  bindings.on('stateChange', stateChange);
363
445
 
446
+ jest.spyOn(console, 'log').mockImplementation(() => {});
447
+
364
448
  bindings.onStateChange('unsupported');
365
449
 
366
- assert.calledOnce(stateChange);
367
- assert.calledWith(stateChange, 'unsupported');
450
+ expect(stateChange).toHaveBeenCalledTimes(1);
451
+ expect(stateChange).toHaveBeenCalledWith('unsupported');
452
+ expect(console.log).toHaveBeenCalledTimes(3);
453
+ expect(console.log).toHaveBeenCalledWith(expect.stringContaining('adapter does not support Bluetooth'));
368
454
  });
369
455
  });
370
456
 
371
457
  it('onAddressChange', () => {
372
- const onAddressChange = fake.resolves(null);
458
+ const onAddressChange = jest.fn();
373
459
 
374
460
  bindings.on('addressChange', onAddressChange);
375
461
 
376
462
  bindings.onAddressChange('newAddress');
377
463
 
378
- assert.calledOnce(onAddressChange);
379
- assert.calledWith(onAddressChange, 'newAddress');
464
+ expect(onAddressChange).toHaveBeenCalledTimes(1);
465
+ expect(onAddressChange).toHaveBeenCalledWith('newAddress');
380
466
  });
381
467
 
382
468
  it('onScanParametersSet', () => {
383
- const onScanParametersSet = fake.resolves(null);
469
+ const onScanParametersSet = jest.fn();
384
470
 
385
471
  bindings.on('scanParametersSet', onScanParametersSet);
386
472
 
387
473
  bindings.onScanParametersSet();
388
474
 
389
- assert.calledOnce(onScanParametersSet);
475
+ expect(onScanParametersSet).toHaveBeenCalledTimes(1);
390
476
  });
391
477
 
392
478
  it('onScanStart', () => {
393
- const onScanStart = fake.resolves(null);
479
+ const onScanStart = jest.fn();
394
480
 
395
481
  bindings.on('scanStart', onScanStart);
396
482
 
397
483
  bindings.onScanStart('filterDuplicates');
398
484
 
399
- assert.calledOnce(onScanStart);
400
- assert.calledWith(onScanStart, 'filterDuplicates');
485
+ expect(onScanStart).toHaveBeenCalledTimes(1);
486
+ expect(onScanStart).toHaveBeenCalledWith('filterDuplicates');
401
487
  });
402
488
 
403
489
  it('onScanStop', () => {
404
- const onScanStop = fake.resolves(null);
490
+ const onScanStop = jest.fn();
405
491
 
406
492
  bindings.on('scanStop', onScanStop);
407
493
 
408
494
  bindings.onScanStop();
409
495
 
410
- assert.calledOnce(onScanStop);
496
+ expect(onScanStop).toHaveBeenCalledTimes(1);
411
497
  });
412
498
 
413
499
  describe('onDiscover', () => {
414
500
  it('new device, no scanServiceUuids', () => {
415
- const onDiscover = fake.resolves(null);
501
+ const onDiscover = jest.fn();
416
502
 
417
503
  bindings.on('discover', onDiscover);
418
504
 
@@ -424,19 +510,19 @@ describe('hci-socket bindings', () => {
424
510
  const connectable = 'connectable';
425
511
  const advertisement = 'advertisement';
426
512
  const rssi = 'rssi';
427
- bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi);
513
+ bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi, undefined);
428
514
 
429
515
  const uuid = 'addressasmac';
430
516
  should(bindings._addresses).deepEqual({ [uuid]: address });
431
517
  should(bindings._addresseTypes).deepEqual({ [uuid]: addressType });
432
518
  should(bindings._connectable).deepEqual({ [uuid]: connectable });
433
519
 
434
- assert.calledOnce(onDiscover);
435
- assert.calledWith(onDiscover, uuid, address, addressType, connectable, advertisement, rssi);
520
+ expect(onDiscover).toHaveBeenCalledTimes(1);
521
+ expect(onDiscover).toHaveBeenCalledWith(uuid, address, addressType, connectable, advertisement, rssi, undefined);
436
522
  });
437
523
 
438
524
  it('new device, with matching scanServiceUuids', () => {
439
- const onDiscover = fake.resolves(null);
525
+ const onDiscover = jest.fn();
440
526
 
441
527
  bindings.on('discover', onDiscover);
442
528
 
@@ -450,19 +536,19 @@ describe('hci-socket bindings', () => {
450
536
  serviceUuids: ['service-uuid']
451
537
  };
452
538
  const rssi = 'rssi';
453
- bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi);
539
+ bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi, undefined);
454
540
 
455
541
  const uuid = 'addressasmac';
456
542
  should(bindings._addresses).deepEqual({ [uuid]: address });
457
543
  should(bindings._addresseTypes).deepEqual({ [uuid]: addressType });
458
544
  should(bindings._connectable).deepEqual({ [uuid]: connectable });
459
545
 
460
- assert.calledOnce(onDiscover);
461
- assert.calledWith(onDiscover, uuid, address, addressType, connectable, advertisement, rssi);
546
+ expect(onDiscover).toHaveBeenCalledTimes(1);
547
+ expect(onDiscover).toHaveBeenCalledWith(uuid, address, addressType, connectable, advertisement, rssi, undefined);
462
548
  });
463
549
 
464
550
  it('new device, with non-matching scanServiceUuids', () => {
465
- const onDiscover = fake.resolves(null);
551
+ const onDiscover = jest.fn();
466
552
 
467
553
  bindings.on('discover', onDiscover);
468
554
 
@@ -476,17 +562,17 @@ describe('hci-socket bindings', () => {
476
562
  serviceUuids: ['another-service-uuid']
477
563
  };
478
564
  const rssi = 'rssi';
479
- bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi);
565
+ bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi, undefined);
480
566
 
481
567
  should(bindings._addresses).deepEqual({});
482
568
  should(bindings._addresseTypes).deepEqual({});
483
569
  should(bindings._connectable).deepEqual({});
484
570
 
485
- assert.notCalled(onDiscover);
571
+ expect(onDiscover).not.toHaveBeenCalled();
486
572
  });
487
573
 
488
574
  it('new device, with service data on advertisement', () => {
489
- const onDiscover = fake.resolves(null);
575
+ const onDiscover = jest.fn();
490
576
 
491
577
  bindings.on('discover', onDiscover);
492
578
 
@@ -500,19 +586,19 @@ describe('hci-socket bindings', () => {
500
586
  serviceData: [{ uuid: 'service-uuid' }]
501
587
  };
502
588
  const rssi = 'rssi';
503
- bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi);
589
+ bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi, undefined);
504
590
 
505
591
  const uuid = 'addressasmac';
506
592
  should(bindings._addresses).deepEqual({ [uuid]: address });
507
593
  should(bindings._addresseTypes).deepEqual({ [uuid]: addressType });
508
594
  should(bindings._connectable).deepEqual({ [uuid]: connectable });
509
595
 
510
- assert.calledOnce(onDiscover);
511
- assert.calledWith(onDiscover, uuid, address, addressType, connectable, advertisement, rssi);
596
+ expect(onDiscover).toHaveBeenCalledTimes(1);
597
+ expect(onDiscover).toHaveBeenCalledWith(uuid, address, addressType, connectable, advertisement, rssi, undefined);
512
598
  });
513
599
 
514
600
  it('new device, non matching service data on advertisement', () => {
515
- const onDiscover = fake.resolves(null);
601
+ const onDiscover = jest.fn();
516
602
 
517
603
  bindings.on('discover', onDiscover);
518
604
 
@@ -526,17 +612,17 @@ describe('hci-socket bindings', () => {
526
612
  serviceData: [{ uuid: 'another-service-uuid' }]
527
613
  };
528
614
  const rssi = 'rssi';
529
- bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi);
615
+ bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi, undefined);
530
616
 
531
617
  should(bindings._addresses).deepEqual({});
532
618
  should(bindings._addresseTypes).deepEqual({});
533
619
  should(bindings._connectable).deepEqual({});
534
620
 
535
- assert.notCalled(onDiscover);
621
+ expect(onDiscover).not.toHaveBeenCalled();
536
622
  });
537
623
 
538
624
  it('new device, no services on advertisement', () => {
539
- const onDiscover = fake.resolves(null);
625
+ const onDiscover = jest.fn();
540
626
 
541
627
  bindings.on('discover', onDiscover);
542
628
 
@@ -548,17 +634,17 @@ describe('hci-socket bindings', () => {
548
634
  const connectable = 'connectable';
549
635
  const advertisement = {};
550
636
  const rssi = 'rssi';
551
- bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi);
637
+ bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi, undefined);
552
638
 
553
639
  should(bindings._addresses).deepEqual({});
554
640
  should(bindings._addresseTypes).deepEqual({});
555
641
  should(bindings._connectable).deepEqual({});
556
642
 
557
- assert.notCalled(onDiscover);
643
+ expect(onDiscover).not.toHaveBeenCalled();
558
644
  });
559
645
 
560
646
  it('new device, undefined _scanServiceUuids', () => {
561
- const onDiscover = fake.resolves(null);
647
+ const onDiscover = jest.fn();
562
648
 
563
649
  bindings.on('discover', onDiscover);
564
650
 
@@ -572,13 +658,13 @@ describe('hci-socket bindings', () => {
572
658
  serviceData: [{ uuid: 'service-uuid' }]
573
659
  };
574
660
  const rssi = 'rssi';
575
- bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi);
661
+ bindings.onDiscover(status, address, addressType, connectable, advertisement, rssi, undefined);
576
662
 
577
663
  should(bindings._addresses).deepEqual({});
578
664
  should(bindings._addresseTypes).deepEqual({});
579
665
  should(bindings._connectable).deepEqual({});
580
666
 
581
- assert.notCalled(onDiscover);
667
+ expect(onDiscover).not.toHaveBeenCalled();
582
668
  });
583
669
  });
584
670
 
@@ -590,12 +676,12 @@ describe('hci-socket bindings', () => {
590
676
  const addressType = 'addressType';
591
677
  const address = 'address';
592
678
 
593
- const connectCallback = sinon.spy();
679
+ const connectCallback = jest.fn();
594
680
 
595
681
  bindings.on('connect', connectCallback);
596
682
  bindings.onLeConnComplete(status, handle, role, addressType, address);
597
683
 
598
- assert.notCalled(connectCallback);
684
+ expect(connectCallback).not.toHaveBeenCalled();
599
685
  });
600
686
 
601
687
  it('with right status on master node', () => {
@@ -605,41 +691,42 @@ describe('hci-socket bindings', () => {
605
691
  const addressType = 'addressType';
606
692
  const address = 'address:split:by:separator';
607
693
 
608
- const connectCallback = sinon.spy();
694
+ const connectCallback = jest.fn();
609
695
 
610
696
  bindings.on('connect', connectCallback);
611
697
  bindings.onLeConnComplete(status, handle, role, addressType, address);
612
698
 
613
- clock.tick(0);
614
-
615
- assert.calledOnce(AclStream);
616
- assert.calledOnce(Gatt);
617
- assert.calledOnce(Signaling);
618
-
619
- assert.callCount(gattOnSpy, 17);
620
- assert.calledWithMatch(gattOnSpy, 'mtu', sinon.match.func);
621
- assert.calledWithMatch(gattOnSpy, 'servicesDiscover', sinon.match.func);
622
- assert.calledWithMatch(gattOnSpy, 'servicesDiscovered', sinon.match.func);
623
- assert.calledWithMatch(gattOnSpy, 'includedServicesDiscover', sinon.match.func);
624
- assert.calledWithMatch(gattOnSpy, 'characteristicsDiscover', sinon.match.func);
625
- assert.calledWithMatch(gattOnSpy, 'characteristicsDiscovered', sinon.match.func);
626
- assert.calledWithMatch(gattOnSpy, 'read', sinon.match.func);
627
- assert.calledWithMatch(gattOnSpy, 'write', sinon.match.func);
628
- assert.calledWithMatch(gattOnSpy, 'broadcast', sinon.match.func);
629
- assert.calledWithMatch(gattOnSpy, 'notify', sinon.match.func);
630
- assert.calledWithMatch(gattOnSpy, 'notification', sinon.match.func);
631
- assert.calledWithMatch(gattOnSpy, 'descriptorsDiscover', sinon.match.func);
632
- assert.calledWithMatch(gattOnSpy, 'valueRead', sinon.match.func);
633
- assert.calledWithMatch(gattOnSpy, 'valueWrite', sinon.match.func);
634
- assert.calledWithMatch(gattOnSpy, 'handleRead', sinon.match.func);
635
- assert.calledWithMatch(gattOnSpy, 'handleWrite', sinon.match.func);
636
- assert.calledWithMatch(gattOnSpy, 'handleNotify', sinon.match.func);
637
-
638
- assert.calledOnceWithMatch(signalingOnSpy, 'connectionParameterUpdateRequest', sinon.match.func);
639
-
640
- assert.calledOnceWithExactly(gattExchangeMtuSpy);
641
-
642
- assert.calledOnceWithExactly(connectCallback, 'addresssplitbyseparator', null);
699
+ jest.advanceTimersByTime(0);
700
+
701
+ expect(AclStream).toHaveBeenCalledTimes(1);
702
+ expect(Gatt).toHaveBeenCalledTimes(1);
703
+ expect(Signaling).toHaveBeenCalledTimes(1);
704
+
705
+ expect(Gatt.onMock).toHaveBeenCalledTimes(17);
706
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
707
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
708
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
709
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
710
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
711
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
712
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
713
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
714
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
715
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
716
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
717
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
718
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
719
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
720
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
721
+ expect(Gatt.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
722
+
723
+ expect(Signaling.onMock).toHaveBeenCalledTimes(1);
724
+ expect(Signaling.onMock).toHaveBeenCalledWith(expect.any(String), expect.any(Function));
725
+
726
+ expect(Gatt.exchangeMtuMock).toHaveBeenCalledTimes(1);
727
+
728
+ expect(connectCallback).toHaveBeenCalledTimes(1);
729
+ expect(connectCallback).toHaveBeenCalledWith('addresssplitbyseparator', null);
643
730
 
644
731
  should(bindings._pendingConnectionUuid).equal(null);
645
732
  });
@@ -651,17 +738,20 @@ describe('hci-socket bindings', () => {
651
738
  const addressType = 'addressType';
652
739
  const address = 'address:split:by:separator';
653
740
 
654
- const connectCallback = sinon.spy();
741
+ const connectCallback = jest.fn();
655
742
 
656
743
  bindings._connectionQueue.push({ id: 'pending_uuid' });
657
744
  bindings.on('connect', connectCallback);
658
745
  bindings.onLeConnComplete(status, handle, role, addressType, address);
659
746
 
660
- assert.notCalled(AclStream);
661
- assert.notCalled(Gatt);
662
- assert.notCalled(Signaling);
747
+ expect(AclStream).not.toHaveBeenCalled();
748
+ expect(Gatt).not.toHaveBeenCalled();
749
+ expect(Signaling).not.toHaveBeenCalled();
663
750
 
664
- assert.calledOnceWithMatch(connectCallback, 'pending_uuid', sinon.match({ message: 'custom mapper (0x1)' }));
751
+ expect(connectCallback).toHaveBeenCalledTimes(1);
752
+ expect(connectCallback).toHaveBeenCalledWith('pending_uuid', expect.objectContaining({
753
+ message: 'custom mapper (0x1)'
754
+ }));
665
755
 
666
756
  should(bindings._connectionQueue).length(0);
667
757
  });
@@ -673,17 +763,20 @@ describe('hci-socket bindings', () => {
673
763
  const addressType = 'addressType';
674
764
  const address = 'address:split:by:separator';
675
765
 
676
- const connectCallback = sinon.spy();
766
+ const connectCallback = jest.fn();
677
767
 
678
768
  bindings._connectionQueue.push({ id: 'pending_uuid' });
679
769
  bindings.on('connect', connectCallback);
680
770
  bindings.onLeConnComplete(status, handle, role, addressType, address);
681
771
 
682
- assert.notCalled(AclStream);
683
- assert.notCalled(Gatt);
684
- assert.notCalled(Signaling);
772
+ expect(AclStream).not.toHaveBeenCalled();
773
+ expect(Gatt).not.toHaveBeenCalled();
774
+ expect(Signaling).not.toHaveBeenCalled();
685
775
 
686
- assert.calledOnceWithExactly(connectCallback, 'pending_uuid', sinon.match({ message: 'HCI Error: Unknown (0x2)' }));
776
+ expect(connectCallback).toHaveBeenCalledTimes(1);
777
+ expect(connectCallback).toHaveBeenCalledWith('pending_uuid', expect.objectContaining({
778
+ message: 'HCI Error: Unknown (0x2)'
779
+ }));
687
780
 
688
781
  should(bindings._connectionQueue).length(0);
689
782
  });
@@ -695,7 +788,7 @@ describe('hci-socket bindings', () => {
695
788
  const addressType = 'random';
696
789
  const address = '11:22:33:44:55:66';
697
790
 
698
- const connectCallback = sinon.spy();
791
+ const connectCallback = jest.fn();
699
792
 
700
793
  bindings._addresses = { 'queuedId_1': '112233445566', 'queuedId_2': '998877665544' };
701
794
  bindings._addresseTypes = { 'queuedId_1': 'random', 'queuedId_2': 'public' };
@@ -705,26 +798,92 @@ describe('hci-socket bindings', () => {
705
798
  bindings.on('connect', connectCallback);
706
799
  bindings.onLeConnComplete(status, handle, role, addressType, address);
707
800
 
708
- assert.calledOnceWithExactly(connectCallback, '112233445566', null);
709
- assert.calledWithExactly(createLeConnSpy, '112233445566', 'random', { addressType: 'random' });
710
- assert.calledWithExactly(createLeConnSpy, '998877665544', 'public', { addressType: 'public' });
801
+ expect(connectCallback).toHaveBeenCalledTimes(1);
802
+ expect(connectCallback).toHaveBeenCalledWith('112233445566', null);
803
+ expect(Hci.createLeConnSpy).toHaveBeenCalledTimes(2);
804
+ expect(Hci.createLeConnSpy).toHaveBeenCalledWith('112233445566', 'random', { addressType: 'random' });
805
+ expect(Hci.createLeConnSpy).toHaveBeenCalledWith('998877665544', 'public', { addressType: 'public' });
711
806
 
712
807
  should(bindings._connectionQueue).length(1);
713
808
  });
809
+
810
+ it('with longer connection queue', () => {
811
+ const status = 0;
812
+ const handle = 'handle';
813
+ const role = 0;
814
+ const addressType = 'random';
815
+ const address = '11:22:33:44:55:66';
816
+
817
+ const connectCallback = jest.fn();
818
+
819
+ bindings._addresses = { 'queuedId_1': '112233445566', 'queuedId_2': '998877665544', 'queuedId_3': 'aabbccddeeff' };
820
+ bindings._addresseTypes = { 'queuedId_1': 'random', 'queuedId_2': 'public', 'queuedId_3': 'random' };
821
+ bindings.connect('queuedId_1', { addressType: 'random' });
822
+ bindings.connect('queuedId_2', { addressType: 'public' });
823
+ bindings.connect('queuedId_3', { addressType: 'random' });
824
+
825
+ bindings.on('connect', connectCallback);
826
+ bindings.onLeConnComplete(status, handle, role, addressType, address);
827
+
828
+ expect(connectCallback).toHaveBeenCalledTimes(1);
829
+ expect(connectCallback).toHaveBeenCalledWith('112233445566', null);
830
+ expect(Hci.createLeConnSpy).toHaveBeenCalledTimes(2);
831
+ expect(Hci.createLeConnSpy).toHaveBeenCalledWith('112233445566', 'random', { addressType: 'random' });
832
+ expect(Hci.createLeConnSpy).toHaveBeenCalledWith('998877665544', 'public', { addressType: 'public' });
833
+ expect(bindings._connectionQueue).toHaveLength(2);
834
+ });
835
+
836
+ it('with longer connection queue where 2 connections are completed', () => {
837
+ const status = 0;
838
+ const handle = 'handle';
839
+ const role = 0;
840
+ const addressType = 'random';
841
+ const address = '11:22:33:44:55:66';
842
+
843
+ const status2 = 0;
844
+ const handle2 = 'handle2';
845
+ const role2 = 0;
846
+ const addressType2 = 'public';
847
+ const address2 = '99:88:77:66:55:44';
848
+
849
+ const connectCallback = jest.fn();
850
+
851
+ bindings._addresses = { 'queuedId_1': '112233445566', 'queuedId_2': '998877665544', 'queuedId_3': 'aabbccddeeff' };
852
+ bindings._addresseTypes = { 'queuedId_1': 'random', 'queuedId_2': 'public', 'queuedId_3': 'random' };
853
+ bindings.connect('queuedId_1', { addressType: 'random' });
854
+ bindings.connect('queuedId_2', { addressType: 'public' });
855
+ bindings.connect('queuedId_3', { addressType: 'random' });
856
+
857
+ bindings.on('connect', connectCallback);
858
+
859
+ bindings.onLeConnComplete(status, handle, role, addressType, address);
860
+ bindings.onLeConnComplete(status2, handle2, role2, addressType2, address2);
861
+
862
+ expect(connectCallback).toHaveBeenCalledTimes(2);
863
+
864
+ expect(connectCallback).toHaveBeenCalledWith('112233445566', null);
865
+ expect(connectCallback).toHaveBeenCalledWith('998877665544', null);
866
+
867
+ expect(Hci.createLeConnSpy).toHaveBeenCalledTimes(3);
868
+ expect(Hci.createLeConnSpy).toHaveBeenCalledWith('112233445566', 'random', { addressType: 'random' });
869
+ expect(Hci.createLeConnSpy).toHaveBeenCalledWith('998877665544', 'public', { addressType: 'public' });
870
+ expect(Hci.createLeConnSpy).toHaveBeenCalledWith('aabbccddeeff', 'random', { addressType: 'random' });
871
+ expect(bindings._connectionQueue).toHaveLength(1);
872
+ });
714
873
  });
715
874
 
716
875
  describe('onDisconnComplete', () => {
717
876
  it('handle not found', () => {
718
- const disconnectCallback = sinon.spy();
877
+ const disconnectCallback = jest.fn();
719
878
 
720
879
  bindings.on('disconnect', disconnectCallback);
721
880
  bindings.onDisconnComplete('missing', 'reason');
722
881
 
723
- assert.notCalled(disconnectCallback);
882
+ expect(disconnectCallback).not.toHaveBeenCalled();
724
883
  });
725
884
 
726
885
  it('existing handle', () => {
727
- const disconnectCallback = sinon.spy();
886
+ const disconnectCallback = jest.fn();
728
887
  const handle = 'handle';
729
888
  const anotherHandle = 'another_handle';
730
889
  const uuid = 'uuid';
@@ -732,10 +891,10 @@ describe('hci-socket bindings', () => {
732
891
  const reason = 'reason';
733
892
 
734
893
  const gattSpy = {
735
- removeAllListeners: sinon.spy()
894
+ removeAllListeners: jest.fn()
736
895
  };
737
896
  const signalingSpy = {
738
- removeAllListeners: sinon.spy()
897
+ removeAllListeners: jest.fn()
739
898
  };
740
899
 
741
900
  // Init expected
@@ -757,9 +916,10 @@ describe('hci-socket bindings', () => {
757
916
  bindings.on('disconnect', disconnectCallback);
758
917
  bindings.onDisconnComplete(handle, reason);
759
918
 
760
- assert.calledOnceWithExactly(disconnectCallback, uuid, reason);
761
- assert.calledOnceWithExactly(gattSpy.removeAllListeners);
762
- assert.calledOnceWithExactly(signalingSpy.removeAllListeners);
919
+ expect(disconnectCallback).toHaveBeenCalledTimes(1);
920
+ expect(disconnectCallback).toHaveBeenCalledWith(uuid, reason);
921
+ expect(gattSpy.removeAllListeners).toHaveBeenCalledTimes(1);
922
+ expect(signalingSpy.removeAllListeners).toHaveBeenCalledTimes(1);
763
923
 
764
924
  should(bindings._handles).not.have.keys(uuid, handle);
765
925
  should(bindings._aclStreams).not.have.keys(handle);
@@ -774,62 +934,66 @@ describe('hci-socket bindings', () => {
774
934
  const anotherHandle = 'another_handle';
775
935
  const encrypt = 'encrypt';
776
936
  const aclSpy = {
777
- pushEncrypt: sinon.spy()
937
+ pushEncrypt: jest.fn()
778
938
  };
779
939
 
780
940
  bindings._aclStreams[handle] = aclSpy;
781
941
  bindings.onEncryptChange(anotherHandle, encrypt);
782
942
 
783
- assert.notCalled(aclSpy.pushEncrypt);
943
+ expect(aclSpy.pushEncrypt).not.toHaveBeenCalled();
784
944
  });
785
945
 
786
946
  it('existing handle', () => {
787
947
  const handle = 'handle';
788
948
  const encrypt = 'encrypt';
789
949
  const aclSpy = {
790
- pushEncrypt: sinon.spy()
950
+ pushEncrypt: jest.fn()
791
951
  };
792
952
 
793
953
  bindings._aclStreams[handle] = aclSpy;
794
954
  bindings.onEncryptChange(handle, encrypt);
795
955
 
796
- assert.calledOnceWithExactly(aclSpy.pushEncrypt, encrypt);
956
+ expect(aclSpy.pushEncrypt).toHaveBeenCalledTimes(1);
957
+ expect(aclSpy.pushEncrypt).toHaveBeenCalledWith(encrypt);
797
958
  });
798
959
 
799
960
  it('existing handle no encrypt', () => {
800
961
  const handle = 'handle';
801
962
  const aclSpy = {
802
- pushEncrypt: sinon.spy()
963
+ pushEncrypt: jest.fn()
803
964
  };
804
965
 
805
966
  bindings._aclStreams[handle] = aclSpy;
806
967
  bindings.onEncryptChange(handle);
807
968
 
808
- assert.calledOnceWithExactly(aclSpy.pushEncrypt, undefined);
969
+ expect(aclSpy.pushEncrypt).toHaveBeenCalledTimes(1);
970
+ expect(aclSpy.pushEncrypt).toHaveBeenCalledWith(undefined);
809
971
  });
810
972
  });
811
973
 
812
974
  it('onMtu', () => {
813
975
  const address = 'this:is:an:address';
814
976
  const rssi = 'rssi';
815
- const callback = sinon.spy();
977
+ const callback = jest.fn();
816
978
 
817
979
  bindings.on('onMtu', callback);
818
980
  bindings.onMtu(address, rssi);
819
981
 
820
- assert.calledOnceWithExactly(callback, 'thisisanaddress', rssi);
982
+ expect(callback).toHaveBeenCalledTimes(1);
983
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', rssi);
821
984
  });
822
985
 
823
986
  it('onRssiRead', () => {
824
987
  const handle = 'handle';
825
988
  const rssi = 'rssi';
826
- const callback = sinon.spy();
989
+ const callback = jest.fn();
827
990
 
828
991
  bindings._handles[handle] = 'binding_handle';
829
992
  bindings.on('rssiUpdate', callback);
830
993
  bindings.onRssiRead(handle, rssi);
831
994
 
832
- assert.calledOnceWithExactly(callback, 'binding_handle', rssi);
995
+ expect(callback).toHaveBeenCalledTimes(1);
996
+ expect(callback).toHaveBeenCalledWith('binding_handle', rssi);
833
997
  });
834
998
 
835
999
  describe('onAclDataPkt', () => {
@@ -839,13 +1003,13 @@ describe('hci-socket bindings', () => {
839
1003
  const cid = 'cid';
840
1004
  const data = 'data';
841
1005
  const aclSpy = {
842
- push: sinon.spy()
1006
+ push: jest.fn()
843
1007
  };
844
1008
 
845
1009
  bindings._aclStreams[handle] = aclSpy;
846
1010
  bindings.onAclDataPkt(anotherHandle, cid, data);
847
1011
 
848
- assert.notCalled(aclSpy.push);
1012
+ expect(aclSpy.push).not.toHaveBeenCalled();
849
1013
  });
850
1014
 
851
1015
  it('existing handle', () => {
@@ -853,25 +1017,27 @@ describe('hci-socket bindings', () => {
853
1017
  const cid = 'cid';
854
1018
  const data = 'data';
855
1019
  const aclSpy = {
856
- push: sinon.spy()
1020
+ push: jest.fn()
857
1021
  };
858
1022
 
859
1023
  bindings._aclStreams[handle] = aclSpy;
860
1024
  bindings.onAclDataPkt(handle, cid, data);
861
1025
 
862
- assert.calledOnceWithExactly(aclSpy.push, cid, data);
1026
+ expect(aclSpy.push).toHaveBeenCalledTimes(1);
1027
+ expect(aclSpy.push).toHaveBeenCalledWith(cid, data);
863
1028
  });
864
1029
 
865
1030
  it('existing handle no cid no data', () => {
866
1031
  const handle = 'handle';
867
1032
  const aclSpy = {
868
- push: sinon.spy()
1033
+ push: jest.fn()
869
1034
  };
870
1035
 
871
1036
  bindings._aclStreams[handle] = aclSpy;
872
1037
  bindings.onAclDataPkt(handle);
873
1038
 
874
- assert.calledOnceWithExactly(aclSpy.push, undefined, undefined);
1039
+ expect(aclSpy.push).toHaveBeenCalledTimes(1);
1040
+ expect(aclSpy.push).toHaveBeenCalledWith(undefined, undefined);
875
1041
  });
876
1042
  });
877
1043
 
@@ -882,14 +1048,14 @@ describe('hci-socket bindings', () => {
882
1048
  const anotherHandle = 'another_handle';
883
1049
  const service = 'service';
884
1050
  const gatt = {
885
- addService: sinon.spy()
1051
+ addService: jest.fn()
886
1052
  };
887
1053
 
888
1054
  bindings._handles[peripheralUuid] = anotherHandle;
889
1055
  bindings._gatts[handle] = gatt;
890
1056
  bindings.addService(peripheralUuid, service);
891
1057
 
892
- assert.notCalled(gatt.addService);
1058
+ expect(gatt.addService).not.toHaveBeenCalled();
893
1059
  });
894
1060
 
895
1061
  it('existing gatt', () => {
@@ -897,28 +1063,30 @@ describe('hci-socket bindings', () => {
897
1063
  const handle = 'handle';
898
1064
  const service = 'service';
899
1065
  const gatt = {
900
- addService: sinon.spy()
1066
+ addService: jest.fn()
901
1067
  };
902
1068
 
903
1069
  bindings._handles[peripheralUuid] = handle;
904
1070
  bindings._gatts[handle] = gatt;
905
1071
  bindings.addService(peripheralUuid, service);
906
1072
 
907
- assert.calledOnceWithExactly(gatt.addService, service);
1073
+ expect(gatt.addService).toHaveBeenCalledTimes(1);
1074
+ expect(gatt.addService).toHaveBeenCalledWith(service);
908
1075
  });
909
1076
 
910
1077
  it('existing gatt no service', () => {
911
1078
  const peripheralUuid = 'uuid';
912
1079
  const handle = 'handle';
913
1080
  const gatt = {
914
- addService: sinon.spy()
1081
+ addService: jest.fn()
915
1082
  };
916
1083
 
917
1084
  bindings._handles[peripheralUuid] = handle;
918
1085
  bindings._gatts[handle] = gatt;
919
1086
  bindings.addService(peripheralUuid);
920
1087
 
921
- assert.calledOnceWithExactly(gatt.addService, undefined);
1088
+ expect(gatt.addService).toHaveBeenCalledTimes(1);
1089
+ expect(gatt.addService).toHaveBeenCalledWith(undefined);
922
1090
  });
923
1091
  });
924
1092
 
@@ -929,14 +1097,14 @@ describe('hci-socket bindings', () => {
929
1097
  const anotherHandle = 'another_handle';
930
1098
  const uuids = 'uuids';
931
1099
  const gatt = {
932
- discoverServices: sinon.spy()
1100
+ discoverServices: jest.fn()
933
1101
  };
934
1102
 
935
1103
  bindings._handles[peripheralUuid] = anotherHandle;
936
1104
  bindings._gatts[handle] = gatt;
937
1105
  bindings.discoverServices(peripheralUuid, uuids);
938
1106
 
939
- assert.notCalled(gatt.discoverServices);
1107
+ expect(gatt.discoverServices).not.toHaveBeenCalled();
940
1108
  });
941
1109
 
942
1110
  it('existing gatt', () => {
@@ -944,51 +1112,55 @@ describe('hci-socket bindings', () => {
944
1112
  const handle = 'handle';
945
1113
  const uuids = 'uuids';
946
1114
  const gatt = {
947
- discoverServices: sinon.spy()
1115
+ discoverServices: jest.fn()
948
1116
  };
949
1117
 
950
1118
  bindings._handles[peripheralUuid] = handle;
951
1119
  bindings._gatts[handle] = gatt;
952
1120
  bindings.discoverServices(peripheralUuid, uuids);
953
1121
 
954
- assert.calledOnceWithExactly(gatt.discoverServices, uuids);
1122
+ expect(gatt.discoverServices).toHaveBeenCalledTimes(1);
1123
+ expect(gatt.discoverServices).toHaveBeenCalledWith(uuids);
955
1124
  });
956
1125
 
957
1126
  it('existing gatt no uuids', () => {
958
1127
  const peripheralUuid = 'uuid';
959
1128
  const handle = 'handle';
960
1129
  const gatt = {
961
- discoverServices: sinon.spy()
1130
+ discoverServices: jest.fn()
962
1131
  };
963
1132
 
964
1133
  bindings._handles[peripheralUuid] = handle;
965
1134
  bindings._gatts[handle] = gatt;
966
1135
  bindings.discoverServices(peripheralUuid);
967
1136
 
968
- assert.calledOnceWithExactly(gatt.discoverServices, []);
1137
+ expect(gatt.discoverServices).toHaveBeenCalledTimes(1);
1138
+ expect(gatt.discoverServices).toHaveBeenCalledWith([]);
969
1139
  });
970
1140
  });
971
1141
 
972
1142
  it('onServicesDiscovered', () => {
973
1143
  const address = 'this:is:an:address';
974
1144
  const serviceUuids = 'serviceUuids';
975
- const callback = sinon.spy();
1145
+ const callback = jest.fn();
976
1146
 
977
1147
  bindings.on('servicesDiscover', callback);
978
1148
  bindings.onServicesDiscovered(address, serviceUuids);
979
1149
 
980
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuids);
1150
+ expect(callback).toHaveBeenCalledTimes(1);
1151
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuids);
981
1152
  });
982
1153
 
983
1154
  it('onServicesDiscoveredEX', () => {
984
1155
  const address = 'this:is:an:address';
985
1156
  const serviceUuids = 'serviceUuids';
986
- const callback = sinon.spy();
1157
+ const callback = jest.fn();
987
1158
 
988
1159
  bindings.on('servicesDiscovered', callback);
989
1160
  bindings.onServicesDiscoveredEX(address, serviceUuids);
990
1161
 
991
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuids);
1162
+ expect(callback).toHaveBeenCalledTimes(1);
1163
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuids);
992
1164
  });
993
1165
 
994
1166
  describe('discoverIncludedServices', () => {
@@ -999,14 +1171,14 @@ describe('hci-socket bindings', () => {
999
1171
  const serviceUuid = 'service-uuid';
1000
1172
  const serviceUuids = 'serviceUuids';
1001
1173
  const gatt = {
1002
- discoverIncludedServices: sinon.spy()
1174
+ discoverIncludedServices: jest.fn()
1003
1175
  };
1004
1176
 
1005
1177
  bindings._handles[peripheralUuid] = anotherHandle;
1006
1178
  bindings._gatts[handle] = gatt;
1007
1179
  bindings.discoverIncludedServices(peripheralUuid, serviceUuid, serviceUuids);
1008
1180
 
1009
- assert.notCalled(gatt.discoverIncludedServices);
1181
+ expect(gatt.discoverIncludedServices).not.toHaveBeenCalled();
1010
1182
  });
1011
1183
 
1012
1184
  it('existing gatt', () => {
@@ -1015,14 +1187,15 @@ describe('hci-socket bindings', () => {
1015
1187
  const serviceUuid = 'service-uuid';
1016
1188
  const serviceUuids = 'serviceUuids';
1017
1189
  const gatt = {
1018
- discoverIncludedServices: sinon.spy()
1190
+ discoverIncludedServices: jest.fn()
1019
1191
  };
1020
1192
 
1021
1193
  bindings._handles[peripheralUuid] = handle;
1022
1194
  bindings._gatts[handle] = gatt;
1023
1195
  bindings.discoverIncludedServices(peripheralUuid, serviceUuid, serviceUuids);
1024
1196
 
1025
- assert.calledOnceWithExactly(gatt.discoverIncludedServices, serviceUuid, serviceUuids);
1197
+ expect(gatt.discoverIncludedServices).toHaveBeenCalledTimes(1);
1198
+ expect(gatt.discoverIncludedServices).toHaveBeenCalledWith(serviceUuid, serviceUuids);
1026
1199
  });
1027
1200
 
1028
1201
  it('existing gatt no uuids', () => {
@@ -1030,14 +1203,15 @@ describe('hci-socket bindings', () => {
1030
1203
  const handle = 'handle';
1031
1204
  const serviceUuid = 'service-uuid';
1032
1205
  const gatt = {
1033
- discoverIncludedServices: sinon.spy()
1206
+ discoverIncludedServices: jest.fn()
1034
1207
  };
1035
1208
 
1036
1209
  bindings._handles[peripheralUuid] = handle;
1037
1210
  bindings._gatts[handle] = gatt;
1038
1211
  bindings.discoverIncludedServices(peripheralUuid, serviceUuid);
1039
1212
 
1040
- assert.calledOnceWithExactly(gatt.discoverIncludedServices, serviceUuid, []);
1213
+ expect(gatt.discoverIncludedServices).toHaveBeenCalledTimes(1);
1214
+ expect(gatt.discoverIncludedServices).toHaveBeenCalledWith(serviceUuid, []);
1041
1215
  });
1042
1216
  });
1043
1217
 
@@ -1045,12 +1219,13 @@ describe('hci-socket bindings', () => {
1045
1219
  const address = 'this:is:an:address';
1046
1220
  const serviceUuid = 'serviceUuid';
1047
1221
  const includedServiceUuids = 'includedServiceUuids';
1048
- const callback = sinon.spy();
1222
+ const callback = jest.fn();
1049
1223
 
1050
1224
  bindings.on('includedServicesDiscover', callback);
1051
1225
  bindings.onIncludedServicesDiscovered(address, serviceUuid, includedServiceUuids);
1052
1226
 
1053
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, includedServiceUuids);
1227
+ expect(callback).toHaveBeenCalledTimes(1);
1228
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, includedServiceUuids);
1054
1229
  });
1055
1230
 
1056
1231
  describe('addCharacteristics', () => {
@@ -1061,14 +1236,14 @@ describe('hci-socket bindings', () => {
1061
1236
  const serviceUuid = 'serviceUuid';
1062
1237
  const characteristics = 'characteristics';
1063
1238
  const gatt = {
1064
- addCharacteristics: sinon.spy()
1239
+ addCharacteristics: jest.fn()
1065
1240
  };
1066
1241
 
1067
1242
  bindings._handles[peripheralUuid] = anotherHandle;
1068
1243
  bindings._gatts[handle] = gatt;
1069
1244
  bindings.addCharacteristics(peripheralUuid, serviceUuid, characteristics);
1070
1245
 
1071
- assert.notCalled(gatt.addCharacteristics);
1246
+ expect(gatt.addCharacteristics).not.toHaveBeenCalled();
1072
1247
  });
1073
1248
 
1074
1249
  it('existing gatt', () => {
@@ -1077,28 +1252,30 @@ describe('hci-socket bindings', () => {
1077
1252
  const serviceUuid = 'serviceUuid';
1078
1253
  const characteristics = 'characteristics';
1079
1254
  const gatt = {
1080
- addCharacteristics: sinon.spy()
1255
+ addCharacteristics: jest.fn()
1081
1256
  };
1082
1257
 
1083
1258
  bindings._handles[peripheralUuid] = handle;
1084
1259
  bindings._gatts[handle] = gatt;
1085
1260
  bindings.addCharacteristics(peripheralUuid, serviceUuid, characteristics);
1086
1261
 
1087
- assert.calledOnceWithExactly(gatt.addCharacteristics, serviceUuid, characteristics);
1262
+ expect(gatt.addCharacteristics).toHaveBeenCalledTimes(1);
1263
+ expect(gatt.addCharacteristics).toHaveBeenCalledWith(serviceUuid, characteristics);
1088
1264
  });
1089
1265
 
1090
1266
  it('existing gatt no serviceUuid no characteristics', () => {
1091
1267
  const peripheralUuid = 'uuid';
1092
1268
  const handle = 'handle';
1093
1269
  const gatt = {
1094
- addCharacteristics: sinon.spy()
1270
+ addCharacteristics: jest.fn()
1095
1271
  };
1096
1272
 
1097
1273
  bindings._handles[peripheralUuid] = handle;
1098
1274
  bindings._gatts[handle] = gatt;
1099
1275
  bindings.addCharacteristics(peripheralUuid);
1100
1276
 
1101
- assert.calledOnceWithExactly(gatt.addCharacteristics, undefined, undefined);
1277
+ expect(gatt.addCharacteristics).toHaveBeenCalledTimes(1);
1278
+ expect(gatt.addCharacteristics).toHaveBeenCalledWith(undefined, undefined);
1102
1279
  });
1103
1280
  });
1104
1281
 
@@ -1110,14 +1287,14 @@ describe('hci-socket bindings', () => {
1110
1287
  const serviceUuid = 'serviceUuid';
1111
1288
  const characteristicUuids = 'characteristics';
1112
1289
  const gatt = {
1113
- discoverCharacteristics: sinon.spy()
1290
+ discoverCharacteristics: jest.fn()
1114
1291
  };
1115
1292
 
1116
1293
  bindings._handles[peripheralUuid] = anotherHandle;
1117
1294
  bindings._gatts[handle] = gatt;
1118
1295
  bindings.discoverCharacteristics(peripheralUuid, serviceUuid, characteristicUuids);
1119
1296
 
1120
- assert.notCalled(gatt.discoverCharacteristics);
1297
+ expect(gatt.discoverCharacteristics).not.toHaveBeenCalled();
1121
1298
  });
1122
1299
 
1123
1300
  it('existing gatt', () => {
@@ -1126,14 +1303,15 @@ describe('hci-socket bindings', () => {
1126
1303
  const serviceUuid = 'serviceUuid';
1127
1304
  const characteristicUuids = 'characteristics';
1128
1305
  const gatt = {
1129
- discoverCharacteristics: sinon.spy()
1306
+ discoverCharacteristics: jest.fn()
1130
1307
  };
1131
1308
 
1132
1309
  bindings._handles[peripheralUuid] = handle;
1133
1310
  bindings._gatts[handle] = gatt;
1134
1311
  bindings.discoverCharacteristics(peripheralUuid, serviceUuid, characteristicUuids);
1135
1312
 
1136
- assert.calledOnceWithExactly(gatt.discoverCharacteristics, serviceUuid, characteristicUuids);
1313
+ expect(gatt.discoverCharacteristics).toHaveBeenCalledTimes(1);
1314
+ expect(gatt.discoverCharacteristics).toHaveBeenCalledWith(serviceUuid, characteristicUuids);
1137
1315
  });
1138
1316
 
1139
1317
  it('existing gatt no uuids', () => {
@@ -1141,14 +1319,15 @@ describe('hci-socket bindings', () => {
1141
1319
  const handle = 'handle';
1142
1320
  const serviceUuid = 'serviceUuid';
1143
1321
  const gatt = {
1144
- discoverCharacteristics: sinon.spy()
1322
+ discoverCharacteristics: jest.fn()
1145
1323
  };
1146
1324
 
1147
1325
  bindings._handles[peripheralUuid] = handle;
1148
1326
  bindings._gatts[handle] = gatt;
1149
1327
  bindings.discoverCharacteristics(peripheralUuid, serviceUuid);
1150
1328
 
1151
- assert.calledOnceWithExactly(gatt.discoverCharacteristics, serviceUuid, []);
1329
+ expect(gatt.discoverCharacteristics).toHaveBeenCalledTimes(1);
1330
+ expect(gatt.discoverCharacteristics).toHaveBeenCalledWith(serviceUuid, []);
1152
1331
  });
1153
1332
  });
1154
1333
 
@@ -1156,24 +1335,26 @@ describe('hci-socket bindings', () => {
1156
1335
  const address = 'this:is:an:address';
1157
1336
  const serviceUuid = 'serviceUuid';
1158
1337
  const characteristics = 'characteristics';
1159
- const callback = sinon.spy();
1338
+ const callback = jest.fn();
1160
1339
 
1161
1340
  bindings.on('characteristicsDiscover', callback);
1162
1341
  bindings.onCharacteristicsDiscovered(address, serviceUuid, characteristics);
1163
1342
 
1164
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, characteristics);
1343
+ expect(callback).toHaveBeenCalledTimes(1);
1344
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, characteristics);
1165
1345
  });
1166
1346
 
1167
1347
  it('onCharacteristicsDiscoveredEX', () => {
1168
1348
  const address = 'this:is:an:address';
1169
1349
  const serviceUuid = 'serviceUuid';
1170
1350
  const characteristics = 'characteristics';
1171
- const callback = sinon.spy();
1351
+ const callback = jest.fn();
1172
1352
 
1173
1353
  bindings.on('characteristicsDiscovered', callback);
1174
1354
  bindings.onCharacteristicsDiscoveredEX(address, serviceUuid, characteristics);
1175
1355
 
1176
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, characteristics);
1356
+ expect(callback).toHaveBeenCalledTimes(1);
1357
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, characteristics);
1177
1358
  });
1178
1359
 
1179
1360
  describe('read', () => {
@@ -1184,14 +1365,14 @@ describe('hci-socket bindings', () => {
1184
1365
  const serviceUuid = 'serviceUuid';
1185
1366
  const characteristicUuid = 'characteristic';
1186
1367
  const gatt = {
1187
- read: sinon.spy()
1368
+ read: jest.fn()
1188
1369
  };
1189
1370
 
1190
1371
  bindings._handles[peripheralUuid] = anotherHandle;
1191
1372
  bindings._gatts[handle] = gatt;
1192
1373
  bindings.read(peripheralUuid, serviceUuid, characteristicUuid);
1193
1374
 
1194
- assert.notCalled(gatt.read);
1375
+ expect(gatt.read).not.toHaveBeenCalled();
1195
1376
  });
1196
1377
 
1197
1378
  it('existing gatt', () => {
@@ -1200,28 +1381,30 @@ describe('hci-socket bindings', () => {
1200
1381
  const serviceUuid = 'serviceUuid';
1201
1382
  const characteristicUuid = 'characteristics';
1202
1383
  const gatt = {
1203
- read: sinon.spy()
1384
+ read: jest.fn()
1204
1385
  };
1205
1386
 
1206
1387
  bindings._handles[peripheralUuid] = handle;
1207
1388
  bindings._gatts[handle] = gatt;
1208
1389
  bindings.read(peripheralUuid, serviceUuid, characteristicUuid);
1209
1390
 
1210
- assert.calledOnceWithExactly(gatt.read, serviceUuid, characteristicUuid);
1391
+ expect(gatt.read).toHaveBeenCalledTimes(1);
1392
+ expect(gatt.read).toHaveBeenCalledWith(serviceUuid, characteristicUuid);
1211
1393
  });
1212
1394
 
1213
1395
  it('existing gatt no uuids', () => {
1214
1396
  const peripheralUuid = 'uuid';
1215
1397
  const handle = 'handle';
1216
1398
  const gatt = {
1217
- read: sinon.spy()
1399
+ read: jest.fn()
1218
1400
  };
1219
1401
 
1220
1402
  bindings._handles[peripheralUuid] = handle;
1221
1403
  bindings._gatts[handle] = gatt;
1222
1404
  bindings.read(peripheralUuid);
1223
1405
 
1224
- assert.calledOnceWithExactly(gatt.read, undefined, undefined);
1406
+ expect(gatt.read).toHaveBeenCalledTimes(1);
1407
+ expect(gatt.read).toHaveBeenCalledWith(undefined, undefined);
1225
1408
  });
1226
1409
  });
1227
1410
 
@@ -1230,12 +1413,13 @@ describe('hci-socket bindings', () => {
1230
1413
  const serviceUuid = 'serviceUuid';
1231
1414
  const characteristicUuid = 'characteristics';
1232
1415
  const data = 'data';
1233
- const callback = sinon.spy();
1416
+ const callback = jest.fn();
1234
1417
 
1235
1418
  bindings.on('read', callback);
1236
1419
  bindings.onRead(address, serviceUuid, characteristicUuid, data);
1237
1420
 
1238
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, characteristicUuid, data, false);
1421
+ expect(callback).toHaveBeenCalledTimes(1);
1422
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, characteristicUuid, data, false);
1239
1423
  });
1240
1424
 
1241
1425
  describe('write', () => {
@@ -1249,14 +1433,14 @@ describe('hci-socket bindings', () => {
1249
1433
  const withoutResponse = true;
1250
1434
 
1251
1435
  const gatt = {
1252
- write: sinon.spy()
1436
+ write: jest.fn()
1253
1437
  };
1254
1438
 
1255
1439
  bindings._handles[peripheralUuid] = anotherHandle;
1256
1440
  bindings._gatts[handle] = gatt;
1257
1441
  bindings.write(peripheralUuid, serviceUuid, characteristicUuid, data, withoutResponse);
1258
1442
 
1259
- assert.notCalled(gatt.write);
1443
+ expect(gatt.write).not.toHaveBeenCalled();
1260
1444
  });
1261
1445
 
1262
1446
  it('existing gatt', () => {
@@ -1267,28 +1451,30 @@ describe('hci-socket bindings', () => {
1267
1451
  const data = 'data';
1268
1452
  const withoutResponse = true;
1269
1453
  const gatt = {
1270
- write: sinon.spy()
1454
+ write: jest.fn()
1271
1455
  };
1272
1456
 
1273
1457
  bindings._handles[peripheralUuid] = handle;
1274
1458
  bindings._gatts[handle] = gatt;
1275
1459
  bindings.write(peripheralUuid, serviceUuid, characteristicUuid, data, withoutResponse);
1276
1460
 
1277
- assert.calledOnceWithExactly(gatt.write, serviceUuid, characteristicUuid, data, withoutResponse);
1461
+ expect(gatt.write).toHaveBeenCalledTimes(1);
1462
+ expect(gatt.write).toHaveBeenCalledWith(serviceUuid, characteristicUuid, data, withoutResponse);
1278
1463
  });
1279
1464
 
1280
1465
  it('existing gatt no uuids', () => {
1281
1466
  const peripheralUuid = 'uuid';
1282
1467
  const handle = 'handle';
1283
1468
  const gatt = {
1284
- write: sinon.spy()
1469
+ write: jest.fn()
1285
1470
  };
1286
1471
 
1287
1472
  bindings._handles[peripheralUuid] = handle;
1288
1473
  bindings._gatts[handle] = gatt;
1289
1474
  bindings.write(peripheralUuid);
1290
1475
 
1291
- assert.calledOnceWithExactly(gatt.write, undefined, undefined, undefined, undefined);
1476
+ expect(gatt.write).toHaveBeenCalledTimes(1);
1477
+ expect(gatt.write).toHaveBeenCalledWith(undefined, undefined, undefined, undefined);
1292
1478
  });
1293
1479
  });
1294
1480
 
@@ -1296,12 +1482,13 @@ describe('hci-socket bindings', () => {
1296
1482
  const address = 'this:is:an:address';
1297
1483
  const serviceUuid = 'serviceUuid';
1298
1484
  const characteristicUuid = 'characteristics';
1299
- const callback = sinon.spy();
1485
+ const callback = jest.fn();
1300
1486
 
1301
1487
  bindings.on('write', callback);
1302
1488
  bindings.onWrite(address, serviceUuid, characteristicUuid);
1303
1489
 
1304
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, characteristicUuid);
1490
+ expect(callback).toHaveBeenCalledTimes(1);
1491
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, characteristicUuid);
1305
1492
  });
1306
1493
 
1307
1494
  describe('broadcast', () => {
@@ -1313,14 +1500,14 @@ describe('hci-socket bindings', () => {
1313
1500
  const characteristicUuid = 'characteristic';
1314
1501
  const broadcast = 'broadcast';
1315
1502
  const gatt = {
1316
- broadcast: sinon.spy()
1503
+ broadcast: jest.fn()
1317
1504
  };
1318
1505
 
1319
1506
  bindings._handles[peripheralUuid] = anotherHandle;
1320
1507
  bindings._gatts[handle] = gatt;
1321
1508
  bindings.broadcast(peripheralUuid, serviceUuid, characteristicUuid, broadcast);
1322
1509
 
1323
- assert.notCalled(gatt.broadcast);
1510
+ expect(gatt.broadcast).not.toHaveBeenCalled();
1324
1511
  });
1325
1512
 
1326
1513
  it('existing gatt', () => {
@@ -1330,28 +1517,30 @@ describe('hci-socket bindings', () => {
1330
1517
  const characteristicUuid = 'characteristics';
1331
1518
  const broadcast = 'broadcast';
1332
1519
  const gatt = {
1333
- broadcast: sinon.spy()
1520
+ broadcast: jest.fn()
1334
1521
  };
1335
1522
 
1336
1523
  bindings._handles[peripheralUuid] = handle;
1337
1524
  bindings._gatts[handle] = gatt;
1338
1525
  bindings.broadcast(peripheralUuid, serviceUuid, characteristicUuid, broadcast);
1339
1526
 
1340
- assert.calledOnceWithExactly(gatt.broadcast, serviceUuid, characteristicUuid, broadcast);
1527
+ expect(gatt.broadcast).toHaveBeenCalledTimes(1);
1528
+ expect(gatt.broadcast).toHaveBeenCalledWith(serviceUuid, characteristicUuid, broadcast);
1341
1529
  });
1342
1530
 
1343
1531
  it('existing gatt no uuids', () => {
1344
1532
  const peripheralUuid = 'uuid';
1345
1533
  const handle = 'handle';
1346
1534
  const gatt = {
1347
- broadcast: sinon.spy()
1535
+ broadcast: jest.fn()
1348
1536
  };
1349
1537
 
1350
1538
  bindings._handles[peripheralUuid] = handle;
1351
1539
  bindings._gatts[handle] = gatt;
1352
1540
  bindings.broadcast(peripheralUuid);
1353
1541
 
1354
- assert.calledOnceWithExactly(gatt.broadcast, undefined, undefined, undefined);
1542
+ expect(gatt.broadcast).toHaveBeenCalledTimes(1);
1543
+ expect(gatt.broadcast).toHaveBeenCalledWith(undefined, undefined, undefined);
1355
1544
  });
1356
1545
  });
1357
1546
 
@@ -1360,12 +1549,13 @@ describe('hci-socket bindings', () => {
1360
1549
  const serviceUuid = 'serviceUuid';
1361
1550
  const characteristicUuid = 'characteristics';
1362
1551
  const state = 'data';
1363
- const callback = sinon.spy();
1552
+ const callback = jest.fn();
1364
1553
 
1365
1554
  bindings.on('broadcast', callback);
1366
1555
  bindings.onBroadcast(address, serviceUuid, characteristicUuid, state);
1367
1556
 
1368
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, characteristicUuid, state);
1557
+ expect(callback).toHaveBeenCalledTimes(1);
1558
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, characteristicUuid, state);
1369
1559
  });
1370
1560
 
1371
1561
  describe('notify', () => {
@@ -1377,14 +1567,14 @@ describe('hci-socket bindings', () => {
1377
1567
  const characteristicUuid = 'characteristic';
1378
1568
  const notify = 'notify';
1379
1569
  const gatt = {
1380
- notify: sinon.spy()
1570
+ notify: jest.fn()
1381
1571
  };
1382
1572
 
1383
1573
  bindings._handles[peripheralUuid] = anotherHandle;
1384
1574
  bindings._gatts[handle] = gatt;
1385
1575
  bindings.notify(peripheralUuid, serviceUuid, characteristicUuid, notify);
1386
1576
 
1387
- assert.notCalled(gatt.notify);
1577
+ expect(gatt.notify).not.toHaveBeenCalled();
1388
1578
  });
1389
1579
 
1390
1580
  it('existing gatt', () => {
@@ -1394,28 +1584,30 @@ describe('hci-socket bindings', () => {
1394
1584
  const characteristicUuid = 'characteristics';
1395
1585
  const notify = 'notify';
1396
1586
  const gatt = {
1397
- notify: sinon.spy()
1587
+ notify: jest.fn()
1398
1588
  };
1399
1589
 
1400
1590
  bindings._handles[peripheralUuid] = handle;
1401
1591
  bindings._gatts[handle] = gatt;
1402
1592
  bindings.notify(peripheralUuid, serviceUuid, characteristicUuid, notify);
1403
1593
 
1404
- assert.calledOnceWithExactly(gatt.notify, serviceUuid, characteristicUuid, notify);
1594
+ expect(gatt.notify).toHaveBeenCalledTimes(1);
1595
+ expect(gatt.notify).toHaveBeenCalledWith(serviceUuid, characteristicUuid, notify);
1405
1596
  });
1406
1597
 
1407
1598
  it('existing gatt no uuids', () => {
1408
1599
  const peripheralUuid = 'uuid';
1409
1600
  const handle = 'handle';
1410
1601
  const gatt = {
1411
- notify: sinon.spy()
1602
+ notify: jest.fn()
1412
1603
  };
1413
1604
 
1414
1605
  bindings._handles[peripheralUuid] = handle;
1415
1606
  bindings._gatts[handle] = gatt;
1416
1607
  bindings.notify(peripheralUuid);
1417
1608
 
1418
- assert.calledOnceWithExactly(gatt.notify, undefined, undefined, undefined);
1609
+ expect(gatt.notify).toHaveBeenCalledTimes(1);
1610
+ expect(gatt.notify).toHaveBeenCalledWith(undefined, undefined, undefined);
1419
1611
  });
1420
1612
  });
1421
1613
 
@@ -1424,12 +1616,13 @@ describe('hci-socket bindings', () => {
1424
1616
  const serviceUuid = 'serviceUuid';
1425
1617
  const characteristicUuid = 'characteristics';
1426
1618
  const state = 'data';
1427
- const callback = sinon.spy();
1619
+ const callback = jest.fn();
1428
1620
 
1429
1621
  bindings.on('notify', callback);
1430
1622
  bindings.onNotify(address, serviceUuid, characteristicUuid, state);
1431
1623
 
1432
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, characteristicUuid, state);
1624
+ expect(callback).toHaveBeenCalledTimes(1);
1625
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, characteristicUuid, state);
1433
1626
  });
1434
1627
 
1435
1628
  it('onNotification', () => {
@@ -1437,12 +1630,13 @@ describe('hci-socket bindings', () => {
1437
1630
  const serviceUuid = 'serviceUuid';
1438
1631
  const characteristicUuid = 'characteristics';
1439
1632
  const data = 'data';
1440
- const callback = sinon.spy();
1633
+ const callback = jest.fn();
1441
1634
 
1442
1635
  bindings.on('read', callback);
1443
1636
  bindings.onNotification(address, serviceUuid, characteristicUuid, data);
1444
1637
 
1445
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, characteristicUuid, data, true);
1638
+ expect(callback).toHaveBeenCalledTimes(1);
1639
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, characteristicUuid, data, true);
1446
1640
  });
1447
1641
 
1448
1642
  describe('discoverDescriptors', () => {
@@ -1453,14 +1647,14 @@ describe('hci-socket bindings', () => {
1453
1647
  const serviceUuid = 'serviceUuid';
1454
1648
  const characteristicUuid = 'characteristic';
1455
1649
  const gatt = {
1456
- discoverDescriptors: sinon.spy()
1650
+ discoverDescriptors: jest.fn()
1457
1651
  };
1458
1652
 
1459
1653
  bindings._handles[peripheralUuid] = anotherHandle;
1460
1654
  bindings._gatts[handle] = gatt;
1461
1655
  bindings.discoverDescriptors(peripheralUuid, serviceUuid, characteristicUuid);
1462
1656
 
1463
- assert.notCalled(gatt.discoverDescriptors);
1657
+ expect(gatt.discoverDescriptors).not.toHaveBeenCalled();
1464
1658
  });
1465
1659
 
1466
1660
  it('existing gatt', () => {
@@ -1469,28 +1663,30 @@ describe('hci-socket bindings', () => {
1469
1663
  const serviceUuid = 'serviceUuid';
1470
1664
  const characteristicUuid = 'characteristics';
1471
1665
  const gatt = {
1472
- discoverDescriptors: sinon.spy()
1666
+ discoverDescriptors: jest.fn()
1473
1667
  };
1474
1668
 
1475
1669
  bindings._handles[peripheralUuid] = handle;
1476
1670
  bindings._gatts[handle] = gatt;
1477
1671
  bindings.discoverDescriptors(peripheralUuid, serviceUuid, characteristicUuid);
1478
1672
 
1479
- assert.calledOnceWithExactly(gatt.discoverDescriptors, serviceUuid, characteristicUuid);
1673
+ expect(gatt.discoverDescriptors).toHaveBeenCalledTimes(1);
1674
+ expect(gatt.discoverDescriptors).toHaveBeenCalledWith(serviceUuid, characteristicUuid);
1480
1675
  });
1481
1676
 
1482
1677
  it('existing gatt no uuids', () => {
1483
1678
  const peripheralUuid = 'uuid';
1484
1679
  const handle = 'handle';
1485
1680
  const gatt = {
1486
- discoverDescriptors: sinon.spy()
1681
+ discoverDescriptors: jest.fn()
1487
1682
  };
1488
1683
 
1489
1684
  bindings._handles[peripheralUuid] = handle;
1490
1685
  bindings._gatts[handle] = gatt;
1491
1686
  bindings.discoverDescriptors(peripheralUuid);
1492
1687
 
1493
- assert.calledOnceWithExactly(gatt.discoverDescriptors, undefined, undefined);
1688
+ expect(gatt.discoverDescriptors).toHaveBeenCalledTimes(1);
1689
+ expect(gatt.discoverDescriptors).toHaveBeenCalledWith(undefined, undefined);
1494
1690
  });
1495
1691
  });
1496
1692
 
@@ -1499,12 +1695,13 @@ describe('hci-socket bindings', () => {
1499
1695
  const serviceUuid = 'serviceUuid';
1500
1696
  const characteristicUuid = 'characteristics';
1501
1697
  const descriptorUuids = 'descriptorUuids';
1502
- const callback = sinon.spy();
1698
+ const callback = jest.fn();
1503
1699
 
1504
1700
  bindings.on('descriptorsDiscover', callback);
1505
1701
  bindings.onDescriptorsDiscovered(address, serviceUuid, characteristicUuid, descriptorUuids);
1506
1702
 
1507
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, characteristicUuid, descriptorUuids);
1703
+ expect(callback).toHaveBeenCalledTimes(1);
1704
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, characteristicUuid, descriptorUuids);
1508
1705
  });
1509
1706
 
1510
1707
  describe('readValue', () => {
@@ -1516,14 +1713,14 @@ describe('hci-socket bindings', () => {
1516
1713
  const characteristicUuid = 'characteristic';
1517
1714
  const descriptorUuid = 'descriptorUuid';
1518
1715
  const gatt = {
1519
- readValue: sinon.spy()
1716
+ readValue: jest.fn()
1520
1717
  };
1521
1718
 
1522
1719
  bindings._handles[peripheralUuid] = anotherHandle;
1523
1720
  bindings._gatts[handle] = gatt;
1524
1721
  bindings.readValue(peripheralUuid, serviceUuid, characteristicUuid, descriptorUuid);
1525
1722
 
1526
- assert.notCalled(gatt.readValue);
1723
+ expect(gatt.readValue).not.toHaveBeenCalled();
1527
1724
  });
1528
1725
 
1529
1726
  it('existing gatt', () => {
@@ -1533,28 +1730,30 @@ describe('hci-socket bindings', () => {
1533
1730
  const characteristicUuid = 'characteristics';
1534
1731
  const descriptorUuid = 'descriptorUuid';
1535
1732
  const gatt = {
1536
- readValue: sinon.spy()
1733
+ readValue: jest.fn()
1537
1734
  };
1538
1735
 
1539
1736
  bindings._handles[peripheralUuid] = handle;
1540
1737
  bindings._gatts[handle] = gatt;
1541
1738
  bindings.readValue(peripheralUuid, serviceUuid, characteristicUuid, descriptorUuid);
1542
1739
 
1543
- assert.calledOnceWithExactly(gatt.readValue, serviceUuid, characteristicUuid, descriptorUuid);
1740
+ expect(gatt.readValue).toHaveBeenCalledTimes(1);
1741
+ expect(gatt.readValue).toHaveBeenCalledWith(serviceUuid, characteristicUuid, descriptorUuid);
1544
1742
  });
1545
1743
 
1546
1744
  it('existing gatt no uuids', () => {
1547
1745
  const peripheralUuid = 'uuid';
1548
1746
  const handle = 'handle';
1549
1747
  const gatt = {
1550
- readValue: sinon.spy()
1748
+ readValue: jest.fn()
1551
1749
  };
1552
1750
 
1553
1751
  bindings._handles[peripheralUuid] = handle;
1554
1752
  bindings._gatts[handle] = gatt;
1555
1753
  bindings.readValue(peripheralUuid);
1556
1754
 
1557
- assert.calledOnceWithExactly(gatt.readValue, undefined, undefined, undefined);
1755
+ expect(gatt.readValue).toHaveBeenCalledTimes(1);
1756
+ expect(gatt.readValue).toHaveBeenCalledWith(undefined, undefined, undefined);
1558
1757
  });
1559
1758
  });
1560
1759
 
@@ -1564,12 +1763,13 @@ describe('hci-socket bindings', () => {
1564
1763
  const characteristicUuid = 'characteristics';
1565
1764
  const descriptorUuid = 'descriptorUuid';
1566
1765
  const data = 'data';
1567
- const callback = sinon.spy();
1766
+ const callback = jest.fn();
1568
1767
 
1569
1768
  bindings.on('valueRead', callback);
1570
1769
  bindings.onValueRead(address, serviceUuid, characteristicUuid, descriptorUuid, data);
1571
1770
 
1572
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, characteristicUuid, descriptorUuid, data);
1771
+ expect(callback).toHaveBeenCalledTimes(1);
1772
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, characteristicUuid, descriptorUuid, data);
1573
1773
  });
1574
1774
 
1575
1775
  describe('writeValue', () => {
@@ -1582,14 +1782,14 @@ describe('hci-socket bindings', () => {
1582
1782
  const descriptorUuid = 'descriptorUuid';
1583
1783
  const data = 'data';
1584
1784
  const gatt = {
1585
- writeValue: sinon.spy()
1785
+ writeValue: jest.fn()
1586
1786
  };
1587
1787
 
1588
1788
  bindings._handles[peripheralUuid] = anotherHandle;
1589
1789
  bindings._gatts[handle] = gatt;
1590
1790
  bindings.writeValue(peripheralUuid, serviceUuid, characteristicUuid, descriptorUuid, data);
1591
1791
 
1592
- assert.notCalled(gatt.writeValue);
1792
+ expect(gatt.writeValue).not.toHaveBeenCalled();
1593
1793
  });
1594
1794
 
1595
1795
  it('existing gatt', () => {
@@ -1600,28 +1800,30 @@ describe('hci-socket bindings', () => {
1600
1800
  const descriptorUuid = 'descriptorUuid';
1601
1801
  const data = 'data';
1602
1802
  const gatt = {
1603
- writeValue: sinon.spy()
1803
+ writeValue: jest.fn()
1604
1804
  };
1605
1805
 
1606
1806
  bindings._handles[peripheralUuid] = handle;
1607
1807
  bindings._gatts[handle] = gatt;
1608
1808
  bindings.writeValue(peripheralUuid, serviceUuid, characteristicUuid, descriptorUuid, data);
1609
1809
 
1610
- assert.calledOnceWithExactly(gatt.writeValue, serviceUuid, characteristicUuid, descriptorUuid, data);
1810
+ expect(gatt.writeValue).toHaveBeenCalledTimes(1);
1811
+ expect(gatt.writeValue).toHaveBeenCalledWith(serviceUuid, characteristicUuid, descriptorUuid, data);
1611
1812
  });
1612
1813
 
1613
1814
  it('existing gatt no uuids', () => {
1614
1815
  const peripheralUuid = 'uuid';
1615
1816
  const handle = 'handle';
1616
1817
  const gatt = {
1617
- writeValue: sinon.spy()
1818
+ writeValue: jest.fn()
1618
1819
  };
1619
1820
 
1620
1821
  bindings._handles[peripheralUuid] = handle;
1621
1822
  bindings._gatts[handle] = gatt;
1622
1823
  bindings.writeValue(peripheralUuid);
1623
1824
 
1624
- assert.calledOnceWithExactly(gatt.writeValue, undefined, undefined, undefined, undefined);
1825
+ expect(gatt.writeValue).toHaveBeenCalledTimes(1);
1826
+ expect(gatt.writeValue).toHaveBeenCalledWith(undefined, undefined, undefined, undefined);
1625
1827
  });
1626
1828
  });
1627
1829
 
@@ -1630,12 +1832,13 @@ describe('hci-socket bindings', () => {
1630
1832
  const serviceUuid = 'serviceUuid';
1631
1833
  const characteristicUuid = 'characteristics';
1632
1834
  const descriptorUuid = 'descriptorUuid';
1633
- const callback = sinon.spy();
1835
+ const callback = jest.fn();
1634
1836
 
1635
1837
  bindings.on('valueWrite', callback);
1636
1838
  bindings.onValueWrite(address, serviceUuid, characteristicUuid, descriptorUuid);
1637
1839
 
1638
- assert.calledOnceWithExactly(callback, 'thisisanaddress', serviceUuid, characteristicUuid, descriptorUuid);
1840
+ expect(callback).toHaveBeenCalledTimes(1);
1841
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', serviceUuid, characteristicUuid, descriptorUuid);
1639
1842
  });
1640
1843
 
1641
1844
  describe('readHandle', () => {
@@ -1645,14 +1848,14 @@ describe('hci-socket bindings', () => {
1645
1848
  const anotherHandle = 'another_handle';
1646
1849
  const attHandle = 'attHandle';
1647
1850
  const gatt = {
1648
- readHandle: sinon.spy()
1851
+ readHandle: jest.fn()
1649
1852
  };
1650
1853
 
1651
1854
  bindings._handles[peripheralUuid] = anotherHandle;
1652
1855
  bindings._gatts[handle] = gatt;
1653
1856
  bindings.readHandle(peripheralUuid, attHandle);
1654
1857
 
1655
- assert.notCalled(gatt.readHandle);
1858
+ expect(gatt.readHandle).not.toHaveBeenCalled();
1656
1859
  });
1657
1860
 
1658
1861
  it('existing gatt', () => {
@@ -1660,28 +1863,30 @@ describe('hci-socket bindings', () => {
1660
1863
  const handle = 'handle';
1661
1864
  const attHandle = 'attHandle';
1662
1865
  const gatt = {
1663
- readHandle: sinon.spy()
1866
+ readHandle: jest.fn()
1664
1867
  };
1665
1868
 
1666
1869
  bindings._handles[peripheralUuid] = handle;
1667
1870
  bindings._gatts[handle] = gatt;
1668
1871
  bindings.readHandle(peripheralUuid, attHandle);
1669
1872
 
1670
- assert.calledOnceWithExactly(gatt.readHandle, attHandle);
1873
+ expect(gatt.readHandle).toHaveBeenCalledTimes(1);
1874
+ expect(gatt.readHandle).toHaveBeenCalledWith(attHandle);
1671
1875
  });
1672
1876
 
1673
1877
  it('existing gatt no uuids', () => {
1674
1878
  const peripheralUuid = 'uuid';
1675
1879
  const handle = 'handle';
1676
1880
  const gatt = {
1677
- readHandle: sinon.spy()
1881
+ readHandle: jest.fn()
1678
1882
  };
1679
1883
 
1680
1884
  bindings._handles[peripheralUuid] = handle;
1681
1885
  bindings._gatts[handle] = gatt;
1682
1886
  bindings.readHandle(peripheralUuid);
1683
1887
 
1684
- assert.calledOnceWithExactly(gatt.readHandle, undefined);
1888
+ expect(gatt.readHandle).toHaveBeenCalledTimes(1);
1889
+ expect(gatt.readHandle).toHaveBeenCalledWith(undefined);
1685
1890
  });
1686
1891
  });
1687
1892
 
@@ -1689,12 +1894,13 @@ describe('hci-socket bindings', () => {
1689
1894
  const address = 'this:is:an:address';
1690
1895
  const handle = 'handle';
1691
1896
  const data = 'data';
1692
- const callback = sinon.spy();
1897
+ const callback = jest.fn();
1693
1898
 
1694
1899
  bindings.on('handleRead', callback);
1695
1900
  bindings.onHandleRead(address, handle, data);
1696
1901
 
1697
- assert.calledOnceWithExactly(callback, 'thisisanaddress', handle, data);
1902
+ expect(callback).toHaveBeenCalledTimes(1);
1903
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', handle, data);
1698
1904
  });
1699
1905
 
1700
1906
  describe('writeHandle', () => {
@@ -1706,14 +1912,14 @@ describe('hci-socket bindings', () => {
1706
1912
  const data = 'data';
1707
1913
  const withoutResponse = true;
1708
1914
  const gatt = {
1709
- writeHandle: sinon.spy()
1915
+ writeHandle: jest.fn()
1710
1916
  };
1711
1917
 
1712
1918
  bindings._handles[peripheralUuid] = anotherHandle;
1713
1919
  bindings._gatts[handle] = gatt;
1714
1920
  bindings.writeHandle(peripheralUuid, attHandle, data, withoutResponse);
1715
1921
 
1716
- assert.notCalled(gatt.writeHandle);
1922
+ expect(gatt.writeHandle).not.toHaveBeenCalled();
1717
1923
  });
1718
1924
 
1719
1925
  it('existing gatt', () => {
@@ -1723,52 +1929,56 @@ describe('hci-socket bindings', () => {
1723
1929
  const data = 'data';
1724
1930
  const withoutResponse = true;
1725
1931
  const gatt = {
1726
- writeHandle: sinon.spy()
1932
+ writeHandle: jest.fn()
1727
1933
  };
1728
1934
 
1729
1935
  bindings._handles[peripheralUuid] = handle;
1730
1936
  bindings._gatts[handle] = gatt;
1731
1937
  bindings.writeHandle(peripheralUuid, attHandle, data, withoutResponse);
1732
1938
 
1733
- assert.calledOnceWithExactly(gatt.writeHandle, attHandle, data, withoutResponse);
1939
+ expect(gatt.writeHandle).toHaveBeenCalledTimes(1);
1940
+ expect(gatt.writeHandle).toHaveBeenCalledWith(attHandle, data, withoutResponse);
1734
1941
  });
1735
1942
 
1736
1943
  it('existing gatt no uuids', () => {
1737
1944
  const peripheralUuid = 'uuid';
1738
1945
  const handle = 'handle';
1739
1946
  const gatt = {
1740
- writeHandle: sinon.spy()
1947
+ writeHandle: jest.fn()
1741
1948
  };
1742
1949
 
1743
1950
  bindings._handles[peripheralUuid] = handle;
1744
1951
  bindings._gatts[handle] = gatt;
1745
1952
  bindings.writeHandle(peripheralUuid);
1746
1953
 
1747
- assert.calledOnceWithExactly(gatt.writeHandle, undefined, undefined, undefined);
1954
+ expect(gatt.writeHandle).toHaveBeenCalledTimes(1);
1955
+ expect(gatt.writeHandle).toHaveBeenCalledWith(undefined, undefined, undefined);
1748
1956
  });
1749
1957
  });
1750
1958
 
1751
1959
  it('onHandleWrite', () => {
1752
1960
  const address = 'this:is:an:address';
1753
1961
  const handle = 'handle';
1754
- const callback = sinon.spy();
1962
+ const callback = jest.fn();
1755
1963
 
1756
1964
  bindings.on('handleWrite', callback);
1757
1965
  bindings.onHandleWrite(address, handle);
1758
1966
 
1759
- assert.calledOnceWithExactly(callback, 'thisisanaddress', handle);
1967
+ expect(callback).toHaveBeenCalledTimes(1);
1968
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', handle);
1760
1969
  });
1761
1970
 
1762
1971
  it('onHandleNotify', () => {
1763
1972
  const address = 'this:is:an:address';
1764
1973
  const handle = 'handle';
1765
1974
  const data = 'data';
1766
- const callback = sinon.spy();
1975
+ const callback = jest.fn();
1767
1976
 
1768
1977
  bindings.on('handleNotify', callback);
1769
1978
  bindings.onHandleNotify(address, handle, data);
1770
1979
 
1771
- assert.calledOnceWithExactly(callback, 'thisisanaddress', handle, data);
1980
+ expect(callback).toHaveBeenCalledTimes(1);
1981
+ expect(callback).toHaveBeenCalledWith('thisisanaddress', handle, data);
1772
1982
  });
1773
1983
 
1774
1984
  it('onConnectionParameterUpdateRequest', () => {
@@ -1777,11 +1987,12 @@ describe('hci-socket bindings', () => {
1777
1987
  const maxInterval = 'maxInterval';
1778
1988
  const latency = 'latency';
1779
1989
  const supervisionTimeout = 'supervisionTimeout';
1780
- const connUpdateLe = sinon.spy();
1990
+ const connUpdateLe = jest.fn();
1781
1991
 
1782
1992
  bindings._hci.connUpdateLe = connUpdateLe;
1783
1993
  bindings.onConnectionParameterUpdateRequest(handle, minInterval, maxInterval, latency, supervisionTimeout);
1784
1994
 
1785
- assert.calledOnceWithExactly(connUpdateLe, handle, minInterval, maxInterval, latency, supervisionTimeout);
1995
+ expect(connUpdateLe).toHaveBeenCalledTimes(1);
1996
+ expect(connUpdateLe).toHaveBeenCalledWith(handle, minInterval, maxInterval, latency, supervisionTimeout);
1786
1997
  });
1787
1998
  });