Skip to content

Commit

Permalink
Add test for undefined accessory values
Browse files Browse the repository at this point in the history
  • Loading branch information
hannseman committed Mar 26, 2018
1 parent ceb6e54 commit 3ccbf03
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/test-accessory.js
Expand Up @@ -81,6 +81,15 @@ describe('accessory', () => {
assert(temperatureSpy.calledWith(null, 23));
});

it('should error on undefined temperature characteristic get value ', () => {
const temperatureSpy = sinon.spy();
const accessory = new this.MiHygrothermographAccessory(mockLogger, {});
const characteristic = this.characteristics.CurrentTemperature;
assert.strictEqual(accessory.temperature, undefined);
characteristic.emit('get', temperatureSpy);
assert(temperatureSpy.calledWith(sinon.match.instanceOf(Error)));
});

it('should answer humidity characteristic get value', () => {
const humiditySpy = sinon.spy();
const accessory = new this.MiHygrothermographAccessory(mockLogger, {});
Expand All @@ -90,6 +99,15 @@ describe('accessory', () => {
assert(humiditySpy.calledWith(null, 30));
});

it('should error on undefined humidity characteristic get value ', () => {
const humiditySpy = sinon.spy();
const accessory = new this.MiHygrothermographAccessory(mockLogger, {});
const characteristic = this.characteristics.CurrentRelativeHumidity;
assert.strictEqual(accessory.humidity, undefined);
characteristic.emit('get', humiditySpy);
assert(humiditySpy.calledWith(sinon.match.instanceOf(Error)));
});

it('should answer low battery characteristic get value', () => {
const lowBatterySpy = sinon.spy();
const accessory = new this.MiHygrothermographAccessory(mockLogger, {});
Expand All @@ -114,6 +132,15 @@ describe('accessory', () => {
assert(batterySpy.calledWith(null, 99));
});

it('should error on undefined battery level characteristic get value ', () => {
const batterySpy = sinon.spy();
const accessory = new this.MiHygrothermographAccessory(mockLogger, {});
const characteristic = this.characteristics.BatteryLevel;
assert.strictEqual(accessory.batteryLevel, undefined);
characteristic.emit('get', batterySpy);
assert(batterySpy.calledWith(sinon.match.instanceOf(Error)));
});

it('should return all services', () => {
const accessory = new this.MiHygrothermographAccessory(mockLogger, {});
const services = accessory.getServices();
Expand Down

0 comments on commit 3ccbf03

Please sign in to comment.