'How to refactor a function that calls a function so that it can be tested using typescript and sinon?

I have the following code

import {
    getIndexDocument
} from "@assets";

class MetaController {
     
    public async exploreIndexDocument(): Promise<Asset | undefined> {
         const {
            result: { assignedDirectories }
         } = await getIndexDocument(this._serviceConfig).catch(err => {
             throw new Error(`[AssetsController] Bad response on discovering index doc because ${err}`);
        });
     }
}

As you can see the exploreIndexDocument is calling function getIndexDocument. I want to write a test for exploreIndexDocument, but I can't stub getIndexDocument using sinon because sinon does not allow you to stub functions. How do I architecture this class to do so?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source