Using Jasmine to spy on a function without an object

后端 未结 6 2069
挽巷
挽巷 2020-11-27 14:52

I\'m new to Jasmine and have just started using it. I have a library js file with lots of functions which are not associated with any object (i.e. are global). How do I go a

6条回答
  •  旧时难觅i
    2020-11-27 15:48

    import * as saveAsFunctions from 'file-saver';
    ..........
    ....... 
    let saveAs;
                beforeEach(() => {
                    saveAs = jasmine.createSpy('saveAs');
                })
                it('should generate the excel on sample request details page', () => {
                    spyOn(saveAsFunctions, 'saveAs').and.callFake(saveAs);
                    expect(saveAsFunctions.saveAs).toHaveBeenCalled();
                })
    

    This worked for me.

提交回复
热议问题