Here's a code snippet that I'm working with:
The component file (component.ts) looks like this:
async ngOnInit() {
import('dom-to-image').then(module => {
const domToImage = module.default;
const node = document.getElementById('some-id');
domToImage.toPng(node).then(dataUrl => {
// The test is not getting over here
}).catch(() => {});
});
}
And the spec file for the same component (component.spec.ts) contains the following:
describe('SomeComponent', () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
....
}).compileComponents();
fixture = TestBed.createComponent(SomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
})
)
it('should create', async () => {
expect(component).toBeTruthy();
});
}
I am struggling with how to mock the promise for domToImage.toPng in my testing. Is there a way to mock it so the test can proceed and resolve the promise?
https://i.sstatic.net/O4Ern.png
Any help or insights on this will be highly appreciated.