You will need to be using the HEAD of the 'tdr' branch of Cylon.js itself.
sudo npm install sinon-chai -g
sudo npm install mocha -g
npm install cylon-firmata
mocha robot.test.js
| var Cylon = require("cylon"); | |
| // Initialize the robot | |
| var robot = Cylon.robot({ | |
| name: 'testor', | |
| // Change the port to the correct port for your Arduino. | |
| connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' }, | |
| device: { name: 'led', driver: 'led', pin: 13 }, | |
| work: function(my) { | |
| // we do our thing here | |
| my.led.toggle(); | |
| every((1).second(), function() { my.led.toggle(); }); | |
| } | |
| }); | |
| // start working | |
| robot.start(); |
| "use strict"; | |
| process.env['CYLON_TEST'] = true; | |
| var chai = require("chai"); | |
| var sinon = require("sinon"); | |
| var sinonChai = require("sinon-chai"); | |
| chai.should(); | |
| chai.use(sinonChai); | |
| var clock = sinon.useFakeTimers(); | |
| var Cylon = require('cylon'); | |
| require("./robot.js"); | |
| describe("robot", function () { | |
| var robot = Cylon.findRobot("testor"); | |
| it("should have work", function () { | |
| return robot.work.should.be.a('function'); | |
| }); | |
| it("should toggle the led after 1 second", function (done) { | |
| var led = robot.devices['led']; | |
| var toggle = sinon.stub(led, 'toggle'); | |
| clock.tick((1).second()); | |
| toggle.should.have.been.called; | |
| done(); | |
| }); | |
| }); |