I'm working with Electron and Johnny-Five to process some data I read with my Arduino Mega 2560 and I'm having some trouble testing my Arduino's connection.
This is the method I want to test (ignore the awful signature):
export let board: Board | null = null;
export function setArduinoBoard(f: (num: number, ...etc: any[]) => void, num: number, ...etc: any[]) {
if (board == null)
board = new Board({...});
board = board.on("ready", () => f(num, etc));
}
And this is my test:
describe.only("setArduinoBoard()", function() {
it("can communicate with the Arduino device", function(done) {
const f = (num: number) => console.log(num);
const spy = sinon.spy(f);
setArduinoBoard(f, 0);
assert(spy.called);
done();
});
});
What I want is for the assertion to wait until the function has been called. And I know it's called eventually because the console outputs 0 but it's only after the assertion fails.