Browse files

- add optional callback to close, close unit-tests, close docs

  • Loading branch information...
1 parent c1caaf6 commit b5cfe453c0c43620cd582d57d0be2286db5d69a9 @sandeepmistry committed Dec 14, 2013
Showing with 32 additions and 1 deletion.
  1. +3 −0 README.md
  2. +5 −1 blink1.js
  3. +24 −0 unit-tests.js
View
3 README.md
@@ -91,6 +91,9 @@ Read pattern line (at the position):
blink1.readPatternLine(position, [callback])
+Close (the underlying HID device):
+
+ blink1.close([callback]);
License
========
View
6 blink1.js
@@ -246,8 +246,12 @@ Blink1.prototype.readPatternLine = function(position, callback) {
});
};
-Blink1.prototype.close = function() {
+Blink1.prototype.close = function(callback) {
this.hidDevice.close();
+
+ if(this._isValidCallback(callback)) {
+ callback();
+ }
};
Blink1.devices = devices;
View
24 unit-tests.js
@@ -30,6 +30,7 @@ describe('blink(1)', function() {
var mockHIDdevices;
var sentFeatureReport;
var recvFeatureReport;
+ var closed = false;
var mockHIDdevice = {
sendFeatureReport: function(featureReport) {
@@ -38,6 +39,10 @@ describe('blink(1)', function() {
getFeatureReport: function(id, length) {
return ((id === FEATURE_REPORT_ID ) && (length === FEATURE_REPORT_LENGTH)) ? recvFeatureReport : null;
+ },
+
+ close: function() {
+ closed = true;
}
};
@@ -743,4 +748,23 @@ describe('blink(1)', function() {
});
});
});
+
+ describe('#Blink1.close', function() {
+ beforeEach(setupBlink1);
+ afterEach(teardownBlink1);
+
+ it('should close HID device', function(done) {
+ blink1.close(done);
+
+ closed.should.eql(true);
+ });
+
+ it('should callback', function(done) {
+ blink1.close(function() {
+ closed.should.eql(true);
+
+ done();
+ });
+ });
+ });
});

0 comments on commit b5cfe45

Please sign in to comment.