Unit Test: increase

This commit is contained in:
Jeronimo Vallelunga 2017-07-16 16:00:45 -03:00
parent bd9569c678
commit 6357a9dd61
6 changed files with 135 additions and 12 deletions

View File

@ -19,10 +19,3 @@ PRs are welcome. To begin developing, do this:
```shell
$ yarn install # or npm install
```
# TODO
- [ ] dotenv
- [ ] https://github.com/vadimdemedes/ink
- [x] bundlesize
- [ ] Prepack
- [ ] https://greenkeeper.io/

View File

@ -18,7 +18,7 @@
"pretest:bundlesize": "npm run uglify",
"posttest:bundlesize": "rm -fR .tmp bundle.js",
"test:watch": "npm test -- --watch",
"test:coverage": "npm test -- --coverage",
"test:coverage": "npm test -- --coverage --forceExit",
"prepublish": "npm run build",
"release": "np",
"example:install": "npm run example:webapp:install",

View File

@ -29,10 +29,6 @@ export default function Characteristic(uuid, Parent, util, descriptor, { encode,
return;
}
if (!this.store) {
callback(this.RESULT_SUCCESS, null);
return;
}
callback(this.RESULT_SUCCESS, this.state);
};

View File

@ -0,0 +1,105 @@
/* global jest, test, expect, beforeEach */
import util from 'util';
import bleno from 'bleno';
import Characteristic from './characteristic';
function Parent({ uuid, properties, descriptors }) {
this.uuid = uuid;
this.properties = properties;
this.descriptors = descriptors;
}
let encode = null;
let decode = null;
beforeEach(() => {
encode = jest.fn().mockReturnValue('mockEncode');
decode = jest.fn().mockReturnValue('mockDecode');
});
test('new Characteristic', () => {
const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
expect(characteristic.uuid).toBe('mockUUID');
expect(characteristic.properties).toEqual(['read', 'write', 'notify']);
expect(characteristic.descriptors).toEqual(['mockDescriptor']);
expect(characteristic.state).toBe(null);
});
test('Characteristic.onWriteRequest: RESULT_ATTR_NOT_LONG', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode });
const callback = jest.fn();
characteristic.onWriteRequest(null, true, false, callback);
expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_ATTR_NOT_LONG);
});
test('Characteristic.onWriteRequest: RESULT_SUCCESS', () => {
let callback = null;
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode });
callback = jest.fn();
const spyOnAction = jest.spyOn(characteristic, 'onAction');
characteristic.onWriteRequest(null, false, false, callback);
expect(spyOnAction).toBeCalledWith('mockDecode');
expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_SUCCESS);
callback = jest.fn();
characteristic.onAction = jest.fn();
characteristic.onWriteRequest(null, false, false, callback);
expect(characteristic.onAction).toBeCalledWith('mockDecode');
expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_SUCCESS);
});
test('Characteristic.onReadRequest: RESULT_ATTR_NOT_LONG', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode });
const callback = jest.fn();
characteristic.onReadRequest(true, callback);
expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_ATTR_NOT_LONG, null);
});
test('Characteristic.onReadRequest: RESULT_SUCCESS', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode });
const callback = jest.fn();
characteristic.onReadRequest(false, callback);
expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_SUCCESS, characteristic.state);
});
test('Characteristic.onSubscribe', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode });
characteristic.onSubscribe(null, 'mockUpdateValueCallback');
expect(characteristic.updateValueCallback).toBe('mockUpdateValueCallback');
});
test('Characteristic.onUnsubscribe', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode });
characteristic.onSubscribe(null, 'mockUpdateValueCallback');
characteristic.onUnsubscribe();
expect(characteristic.updateValueCallback).toBe(null);
});
test('Characteristic.updateState', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode });
characteristic.updateState('mockState');
expect(characteristic.state).toBe('mockEncode');
const updateValueCallback = jest.fn();
characteristic.onSubscribe(null, updateValueCallback);
characteristic.updateState('mockState');
expect(updateValueCallback).toBeCalledWith('mockEncode');
});

View File

@ -0,0 +1,13 @@
/* global test, expect, */
import Descriptor from './descriptor';
function Parent({ uuid, value }) {
return { uuid, value };
}
test('descriptor', () => {
const descriptor = Descriptor('mockUUID', Parent);
expect(descriptor.uuid).toBe('mockUUID');
expect(descriptor.value).toBe('Redux Characteristic.');
});

View File

@ -0,0 +1,16 @@
/* global test, expect, */
import util from 'util';
import Service from './service';
function Parent({ uuid, characteristics }) {
this.uuid = uuid;
this.characteristics = characteristics;
}
test('service', () => {
const service = Service('mockUUID', Parent, util, 'mockCharacteristic');
expect(service.uuid).toBe('mockUUID');
expect(service.characteristics).toEqual(['mockCharacteristic']);
});