Skip to content

Instantly share code, notes, and snippets.

@todgru todgru/module.js
Last active Feb 5, 2019

Embed
What would you like to do?
function foo() {
console.log('foo');
}
function bar() {
foo();
}
module.exports = {
foo,
bar
}
// better?
function foo() {
console.log('foo');
}
module.exports = {
foo,
bar: foo
}
const test = require("ava");
const sinon = require("sinon");
let sandbox;
test.before(t => {
sandbox = sinon.sandbox.create();
});
test.beforeEach(t => {
});
test.afterEach.always(t => {
sandbox.restore();
});
test("bar() return 'fake'", async t => {
t.context.module = require('./module');
t.context.module.foo = sandbox.stub().return("fake");
// This will not call the stub, but the original method. ????
t.is(t.context.module.bar(), 'fake');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.