Skip to content

Instantly share code, notes, and snippets.

@corlaez
Created March 26, 2021 20:59
Show Gist options
  • Save corlaez/12382f97b706c964c24c6e70b45a4991 to your computer and use it in GitHub Desktop.
Save corlaez/12382f97b706c964c24c6e70b45a4991 to your computer and use it in GitHub Desktop.
Sinon usage problem example
const sinon = require("sinon");
const auth = { session: () => "real" };
sinon.stub(auth, "session").callsFake(() => {
return "fake";
});
console.log(auth.session());// fake as expected
const holdSession = auth.session;//hapens in app.js app.use(auth.session);
sinon.restore();
console.log(auth.session()); // real as expected
console.log(holdSession()); // fake ... UNEXPECTED!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment