Reputation: 1980
I have the following class in a parent project (parent project will be a module in child project):
export default class testService {
constructor({loggerFactory,childService}) {
this.logger = loggerFactory.logger
this.child = childService;
}
}
when I run test the test has been failed because the childservice does not exist. the service is exist only if I open the child project that includes the parent module in the node modules
so my question is how can i mock that to prevent failure in test
Upvotes: 0
Views: 79
Reputation: 1610
You can pass in a stub childService
when instantiating the class in your test:
const loggerFactory = {
logger: () => {},
}
const childService = {}
const mockTestService = new testService({loggerFactory, childService});
Upvotes: 2