'how to create instance of class with jest

I am a beginner in writing tests and in jest also. I want to test that this function to be called and return the success promise. I write a unit test for function using jest. The function gets like parameter instance of class that I can't create because its constructor requires parameters that I haven't access. I have a lot of functions that have Session like parametrs. How can test function when you cant provide parametrs for it? Can I mock instance of class or function and handle it without parameter?

async initFlow(session: Session) {
    const nextAtomId = session.userInput.getParam('NEXT_ATOM');
    if (nextAtomId) {
        const nextAtom = await AtomManager.findActiveAtom(nextAtomId);
        if (!session.features.useTerms || ['beforeTerms', 'TermsAndConditions'].includes(nextAtom.type)) {
            return AtomProcessor.processAtom(session, nextAtom);
        }
    }

    const start = await AtomManager.getStartAtom(`${session.botId}`);
    if (!start) {
        throw new Error('Could not find start atom');
    }

    session.user = await UserManager.getGlobalUser(session); // getGlobalUser makes initUser under the hood.
    return AtomProcessor.processAtom(session, start);
}


Sources

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

Source: Stack Overflow

Solution Source