'Jest not implemented for window.open

Jest not implemented for window.open, getting error on the console but unit test is getting pass with console error

a.ts file

myFun(){
 window.open('https://stackoverflow.com/', '_blank');
}

a.spec.ts

providers: [
      {
        useValue: { open: jest.fn() }
      }
    ]
----------------------------------------------
it('should open window on submit ', () => {
      const spy = spyOn(window, 'open').and.callFake(() => {});
      component.submit();
      expect(spy).toHaveBeenCalledWith('https://stackoverflow.com/', '_blank');
    });

Console error

`console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
    Error: Not implemented: window.open
        at module.exports (C:\workspace\guide-ast\fis-my-support\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17)
        at C:\workspace\guide-ast\fis-my-support\node_modules\jsdom\lib\jsdom\browser\Window.js:594:7
        at SafeSubscriber._next (C:\workspace\guide-ast\fis-my-support\apps\ui\src\app\ticket-creation\formly-ticket-page\formly-ticket-page.component.ts:167:18)
        at SafeSubscriber.Object.<anonymous>.SafeSubscriber.__tryOrUnsub (C:\workspace\guide-ast\fis-my-support\node_modules\rxjs\src\internal\Subscriber.ts:265:10)
        at SafeSubscriber.Object.<anonymous>.SafeSubscriber.next (C:\workspace\guide-ast\fis-my-support\node_modules\rxjs\src\internal\Subscriber.ts:207:14)
        at Subscriber.Object.<anonymous>.Subscriber._next (C:\workspace\guide-ast\fis-my-support\node_modules\rxjs\src\internal\Subscriber.ts:139:22)
        at Subscriber.Object.<anonymous>.Subscriber.next (C:\workspace\guide-ast\fis-my-support\node_modules\rxjs\src\internal\Subscriber.ts:99:12)
        at TakeWhileSubscriber.Object.<anonymous>.TakeWhileSubscriber.nextOrComplete (C:\workspace\guide-ast\fis-my-support\node_modules\rxjs\src\internal\operators\takeWhile.ts:102:19)
        at TakeWhileSubscriber.Object.<anonymous>.TakeWhileSubscriber._next (C:\workspace\guide-ast\fis-my-support\node_modules\rxjs\src\internal\operators\takeWhile.ts:96:10)
        at TakeWhileSubscriber.Object.<anonymous>.Subscriber.next (C:\workspace\guide-ast\fis-my-support\node_modules\rxjs\src\internal\Subscriber.ts:99:12) undefined`


Sources

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

Source: Stack Overflow

Solution Source