How to mock/stub instances of other classes passed in the class to be tested in the unit test?

the current project and code structure are as follows

- class A file (root)
    + class B file
        - class C file
// TypeScript
class A {
    private b: B;
    constructor(options) {
        this.b = new B(this);
    }
    otherMethod() {}
}

class B {
    private a: A;
    private c: C;
    constructor(root: A) {
        this.a = root;
        this.c = new C(root);
    }
    otherMethod() {}
}

class C {
    private a: A;
    constructor(root: A) {
        this.a = root;
    }
    handler(param1: boolean, param2: any) {
        if (param1) {
            this.a.otherMethod();
        } else {
            this.otherMethod();
        }
    }
    otherMethod() {}
}

now to test the handler method in C, in order to protect handler from other environments, you should use the root parameter of stub/mock C and the C.otherMethod method called in handler, and then const c = new C (mockedA); c.handler (mockedP1, mockedP2);

what is a little puzzling at the moment is how to stub/mock the root parameter of C?

the first thing that comes to mind is that an instance of An in stub/mock is passed to C, and doing so is equivalent to new an instance of the entire project, which sounds a little wrong.

the second thing that comes to mind is to construct a class equivalent to A. the problem with this is that if An is very large, it is quite troublesome to construct.

in TypeScript, the passed parameters must match the interface to ensure that there are no type errors, so it is stuck here.

also because of another problem caused by the type, how to test the private methods in the class?

Please ask the students who understand the Typescript test to answer the questions. Thank you.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9a3aa-47595.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9a3aa-47595.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?