Skip to content

Commit

Permalink
Tests supporting gh-71
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <[email protected]>
  • Loading branch information
rwaldron committed Apr 15, 2016
1 parent 11d60fc commit 37e419a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
5 changes: 2 additions & 3 deletions node/tessel-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ Tessel.Pin.prototype.removeAllListeners = function(event) {
Tessel.Pin.prototype.addListener = function(mode, callback) {
if (typeof Tessel.Pin.interruptModes[mode] !== 'undefined') {
if (!this.interruptSupported) {
throw new Error('Interrupts are not supported on pin ' + this.pin + '. Pins 2, 5, 6, and 7 on either port support interrupts.');
throw new Error(`Interrupts are not supported on pin ${this.pin}. Pins 2, 5, 6, and 7 on either port support interrupts.`);
}

if ((mode === 'high' || mode === 'low') && !callback.listener) {
Expand All @@ -563,8 +563,7 @@ Tessel.Pin.prototype.addListener = function(mode, callback) {

if (this.interruptMode !== mode) {
if (this.interruptMode) {
throw new Error('Cannot set pin interrupt mode to ' + mode +
'; already listening for ' + this.interruptMode);
throw new Error(`Cannot set pin interrupt mode to ${mode}; already listening for ${this.interruptMode}`);
}
// Set the socket reference so the script doesn't exit
this._port.ref();
Expand Down
62 changes: 62 additions & 0 deletions node/test/unit/tessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,68 @@ exports['Tessel.Pin'] = {
test.done();
},

interruptErroMessages: function(test) {
test.expect(2);

var spy = sandbox.spy();

try {
this.a.pin[0].once('low', spy);
} catch (error) {
test.equal(error.message, 'Interrupts are not supported on pin 0. Pins 2, 5, 6, and 7 on either port support interrupts.');
}

try {
this.a.pin[2].once('rise', spy);
this.a.pin[2].once('fall', spy);
} catch (error) {
test.equal(error.message, 'Cannot set pin interrupt mode to fall; already listening for rise');
}

test.done();
},

levelInterruptInvalidPin: function(test) {
test.expect(16);

var spy = sandbox.spy();

[0, 1, 3, 4].forEach(pinIndex => {
test.throws(() => this.a.pin[pinIndex].once('high', spy));
test.throws(() => this.a.pin[pinIndex].once('low', spy));
test.throws(() => this.b.pin[pinIndex].once('high', spy));
test.throws(() => this.b.pin[pinIndex].once('low', spy));
});

test.done();
},

interruptRiseInvalidPin: function(test) {
test.expect(8);

var spy = sandbox.spy();

[0, 1, 3, 4].forEach(pinIndex => {
test.throws(() => this.a.pin[pinIndex].on('rise', spy));
test.throws(() => this.b.pin[pinIndex].on('rise', spy));
});

test.done();
},

interruptFallInvalidPin: function(test) {
test.expect(8);

var spy = sandbox.spy();

[0, 1, 3, 4].forEach(pinIndex => {
test.throws(() => this.a.pin[pinIndex].on('fall', spy));
test.throws(() => this.b.pin[pinIndex].on('fall', spy));
});

test.done();
},

interruptHigh: function(test) {
test.expect(9);

Expand Down

0 comments on commit 37e419a

Please sign in to comment.