1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Jest not implemented for window.open

Discussão em 'Angular' iniciado por Rijo, Novembro 5, 2024 às 13:32.

  1. Rijo

    Rijo Guest

    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`

    Continue reading...

Compartilhe esta Página