I'm currently using Chai
and Mocha
for testing purposes within my project. I am looking to test the createTreefromFolder function that resides in a module called tree.js
:
export function createTreefromFolder(path: string): string[] {
const files = listFilesFromFolder(path);
const tree: string[] = [createFirstBranch(path)];
files.forEach((file) => {
tree.push(Prefix.VERTICAL.concat(file));
});
return tree;
}
My objective is to simulate the behavior of the listFilesFromFolder
function during testing, so that it returns a specific value.
Within the tests folder, I have the following:
it("creating a unique folder tree", () => {
const expectedArray: string[] = ["🗃️ empty_folder"];
mock("src.tree.listFilesFromFolder").return_value = ["empty_folder"] // mocking here
expect(createTreefromFolder(empty_test_folder_path)).to.eql(expectedArray);
});
Is there a similar method to achieve this as python's unitest.mock.patch functionality?