[ISSUE-11] Test Coverage
This commit is contained in:
parent
aa03b16916
commit
02f9f2278c
|
@ -81,6 +81,8 @@ test('Characteristic.onUnsubscribe', () => {
|
||||||
test('Characteristic.updateState', () => {
|
test('Characteristic.updateState', () => {
|
||||||
const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
|
const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
|
||||||
|
|
||||||
|
characteristic.updateState({ mockState: 'mockState' });
|
||||||
|
|
||||||
const maxValueSize = 10;
|
const maxValueSize = 10;
|
||||||
const updateValueCallback = jest.fn();
|
const updateValueCallback = jest.fn();
|
||||||
characteristic.onSubscribe(maxValueSize, updateValueCallback);
|
characteristic.onSubscribe(maxValueSize, updateValueCallback);
|
||||||
|
|
|
@ -10,7 +10,6 @@ beforeEach(() => {
|
||||||
central = {
|
central = {
|
||||||
connect: jest.fn().mockReturnValue(Promise.resolve()),
|
connect: jest.fn().mockReturnValue(Promise.resolve()),
|
||||||
handler: jest.fn(),
|
handler: jest.fn(),
|
||||||
read: jest.fn().mockReturnValue(Promise.resolve('mockState')),
|
|
||||||
write: jest.fn().mockReturnValue(Promise.resolve()),
|
write: jest.fn().mockReturnValue(Promise.resolve()),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,13 +39,6 @@ export default function Central(
|
||||||
return listerner;
|
return listerner;
|
||||||
});
|
});
|
||||||
|
|
||||||
const read = () => {
|
|
||||||
if (state.server && state.server.connected && state.characteristic) {
|
|
||||||
return state.characteristic.readValue().then(data => decode(data));
|
|
||||||
}
|
|
||||||
return Promise.reject(new Error('Bluetooth: Not Connected'));
|
|
||||||
};
|
|
||||||
|
|
||||||
const write = (action) => {
|
const write = (action) => {
|
||||||
if (!state.server || !state.server.connected || !state.characteristic) return null;
|
if (!state.server || !state.server.connected || !state.characteristic) return null;
|
||||||
const stringify = JSON.stringify(action);
|
const stringify = JSON.stringify(action);
|
||||||
|
@ -58,7 +51,6 @@ export default function Central(
|
||||||
connected: state.server && state.server.connected,
|
connected: state.server && state.server.connected,
|
||||||
connect,
|
connect,
|
||||||
handler,
|
handler,
|
||||||
read,
|
|
||||||
write,
|
write,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,16 +73,22 @@ test('Central: handler', () => {
|
||||||
return expect(promise).resolves.toBe(true);
|
return expect(promise).resolves.toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Central: read', () => {
|
test('Central: handler chunk', () => {
|
||||||
expect.assertions(2);
|
const callback = jest.fn();
|
||||||
|
expect.assertions(3);
|
||||||
|
|
||||||
const promise = central.connect('mockName').then(() => central.read())
|
encoder.decode = jest.fn().mockReturnValue('{"mockDecode":"mockDecode"}');
|
||||||
.then((data) => {
|
central = new Central(bluetooth, encoder, CENTRAL_CONFIG);
|
||||||
expect(characteristic.readValue).toBeCalled();
|
|
||||||
return data;
|
const promise = central.connect('mockName').then(() => central.handler(callback))
|
||||||
|
.then((listerner) => {
|
||||||
|
expect(characteristic.startNotifications).toBeCalled();
|
||||||
|
listerner({ target: { value: 'mockEvent' } });
|
||||||
|
expect(callback.mock.calls.length).toEqual(0);
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
return expect(promise).resolves.toBe('[[[{"mockDecode":"mockDecode"}]]]');
|
return expect(promise).resolves.toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Central: write', () => {
|
test('Central: write', () => {
|
||||||
|
|
Loading…
Reference in New Issue