[ISSUE-11] Test Coverage

This commit is contained in:
Jeronimo Vallelunga 2017-10-25 20:34:58 -03:00
parent aa03b16916
commit 02f9f2278c
4 changed files with 15 additions and 16 deletions

View File

@ -81,6 +81,8 @@ test('Characteristic.onUnsubscribe', () => {
test('Characteristic.updateState', () => {
const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
characteristic.updateState({ mockState: 'mockState' });
const maxValueSize = 10;
const updateValueCallback = jest.fn();
characteristic.onSubscribe(maxValueSize, updateValueCallback);

View File

@ -10,7 +10,6 @@ beforeEach(() => {
central = {
connect: jest.fn().mockReturnValue(Promise.resolve()),
handler: jest.fn(),
read: jest.fn().mockReturnValue(Promise.resolve('mockState')),
write: jest.fn().mockReturnValue(Promise.resolve()),
};
});

View File

@ -39,13 +39,6 @@ export default function Central(
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) => {
if (!state.server || !state.server.connected || !state.characteristic) return null;
const stringify = JSON.stringify(action);
@ -58,7 +51,6 @@ export default function Central(
connected: state.server && state.server.connected,
connect,
handler,
read,
write,
};
}

View File

@ -73,16 +73,22 @@ test('Central: handler', () => {
return expect(promise).resolves.toBe(true);
});
test('Central: read', () => {
expect.assertions(2);
test('Central: handler chunk', () => {
const callback = jest.fn();
expect.assertions(3);
const promise = central.connect('mockName').then(() => central.read())
.then((data) => {
expect(characteristic.readValue).toBeCalled();
return data;
encoder.decode = jest.fn().mockReturnValue('{"mockDecode":"mockDecode"}');
central = new Central(bluetooth, encoder, CENTRAL_CONFIG);
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', () => {