From 01ca3763d813c76b0b7b535fe8795e1fafb45a86 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Tue, 15 Apr 2014 12:53:06 -0300 Subject: [PATCH] add some basic tests for the structure of the API --- test/test.API.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/test.API.js diff --git a/test/test.API.js b/test/test.API.js new file mode 100644 index 000000000..5a334bc32 --- /dev/null +++ b/test/test.API.js @@ -0,0 +1,49 @@ +'use strict'; + +var chai = chai || require('chai'); +var should = chai.should(); +var API = API || require('../API'); + +describe('API', function() { + + it('should have a command called "echo"', function() { + var api = new API(); + should.exist(api.echo); + }); + + it('should have argTypes for every command', function() { + for (var i in API.prototype) { + var f = API.prototype[i]; + if (i[0] != '_' && typeof f == 'function') { + f.argTypes.length.should.be.greaterThan(0); + } + }; + }) + + it('should throw an error for all commands when called with wrong number of arguments', function() { + var api = new API(); + for (var i in API.prototype) { + var f = API.prototype[i]; + if (i[0] != '_' && typeof f == 'function') { + var a = new Array(); + for (var j = 0; j <= f.argTypes.length + 1; j++) { + a.push(0); + } + (function() { + api[i].apply(api, a); + }).should.throw(); + } + }; + }); + + it('should have a callback in the arguments on every command', function() { + for (var i in API.prototype) { + var f = API.prototype[i]; + if (i[0] != '_' && typeof f == 'function') { + f.argTypes[f.argTypes.length-1][0].should.equal('callback'); + f.argTypes[f.argTypes.length-1][1].should.equal('function'); + } + } + }); + +});