jest not implemented window.alert()

前端 未结 3 530
春和景丽
春和景丽 2021-01-03 18:50

i have written test for my api with jest . i added function that calls my api in test file as below:

import AuthManager from \"../Client/Modules/Auth/AuthMan         


        
3条回答
  •  轮回少年
    2021-01-03 19:02

    I faced with window.confirm This is my solution for angular fw.

    let spyOnWindow: jasmine.Spy;
    
    beforeEach((() => {
        TestBed.configureTestingModule({
          declarations: [...],
          imports: [...],
          providers: [...]
        }).compileComponents().then(() => {
          ...
          spyOnWindow = spyOn(window,'confirm');
          ...
        });
    

    Some test case

    it('showModal testing function with delete an event', () => {
    spyOnWindow.and.returnValue(true);
    ...
    }
    
    it('showModal testing function with delete an event', () => {
    spyOnWindow.and.returnValue(false);
    ...
    }
    

提交回复
热议问题