livestream icon indicating copy to clipboard operation
livestream copied to clipboard

Episode 2020-05-19: How to use spies with sinon

Open wolfgang-wdw opened this issue 4 years ago • 2 comments

(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.

wolfgang-wdw avatar May 22 '20 08:05 wolfgang-wdw

Thanks! I couldn't figure it out just from looking at the documentation.

jamesshore avatar May 22 '20 08:05 jamesshore

I'm going to leave this open for future viewers.

jamesshore avatar May 22 '20 08:05 jamesshore