livestream
livestream copied to clipboard
Episode 2020-05-19: How to use spies with sinon
(Refers to Lunch & Learn: Mocks & Spies). Code here.
Hi James, thanks for doing these videos, very helpful indeed! Not sure if you are even looking for this kind of feedback, but just as an aside, I had an itch to reproduce the arrange/act/assert behavior in _app.test.js uing sinon. Only setup and assertOutput need to be changed:
function setup(args) {
const commandLine = sinon.stub(CommandLine.create());
const app = App.create(commandLine);
commandLine.args.returns(args);
return { commandLine, app };
}
function assertOutput(commandLine, expectedOutput) {
sinon.assert.calledWith(commandLine.writeOutput, expectedOutput);
}
I admit it still seems weird to have a "stub" be able to assert calls, which makes the td version a bit clearer.
Thanks! I couldn't figure it out just from looking at the documentation.
I'm going to leave this open for future viewers.