Skip to content

Instantly share code, notes, and snippets.

@schipiga
Last active January 15, 2020 20:44
Show Gist options
  • Save schipiga/c294ccb34c1a967f3ba703e9ff8327a4 to your computer and use it in GitHub Desktop.
Save schipiga/c294ccb34c1a967f3ba703e9ff8327a4 to your computer and use it in GitHub Desktop.
"use strict";
const myModule = rehire("./myModule", {
"fs": { existsSync: () => true },
});
suite("myModule", () => {
afterChunk(() => {
myModule.__reset__();
});
test("mock internal function", () => {
chunk("get it", () => {
const _summarize = myModule.__get__('_summarize');
expect(_summarize(1, 2)).to.be.equal(3);
});
chunk("set it", () => {
myModule.__set__('_summarize', () => 5);
expect(myModule.summarize(1, 2)).to.be.equal(5);
});
});
test("mock third-party module", () => {
chunk(() => {
expect(myModule.isPathExists('/bla/bla/bla')).to.be.true;
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment