I'm fairly new to angular and also to jest. I have a class like this:
import {CloudWatchLogs} from 'aws-sdk/clients/browser_default';
import {isNullOrUndefined} from 'util';
@Injectable()
export class MyService {
private cloudWatchLogs: CloudWatchLogs = null;
constructor() {}
startService() {
setupService();
myOtherTask();
}
private setUpService() {
if (!isNullOrUndefined(this.cloudWatchLogs)) {
this.cloudWatchLogs = new CloudWatchLogs();
// setup options
}
}
private void myOtherTask() {
this.cloudWatchLogs.doSomething();
this.cloudWatchLogs.doSomethingElse();
}
}
and i'm trying use Jest to run unit tests against MyService. What i'd like to know is, is it possible to mock the CloudWatchLogs methods for doSomething and doSomethingElse with the way this class has been written as it is, bearing in mind that CloudWatchLogs is a javascript object, and not an angular injectable.
The only solution i can see to being able to mock CloudWatchLogs is to create an injectable service that wraps the CloudWatchLogs, and then injecting this into MyService.