Jest createSpyObj

前端 未结 3 1173
青春惊慌失措
青春惊慌失措 2021-01-02 06:03

With Chai, you can create a spy object as follows:

chai.spy.object([ \'push\', \'pop\' ]);

With jasmine, you can use:

jasmi         


        
3条回答
  •  一向
    一向 (楼主)
    2021-01-02 06:37

    I've written a very quick createSpyObj function for jest, to support the old project. Basically ported from Jasmine's implementation.

    export const createSpyObj = (baseName, methodNames): { [key: string]: Mock } => {
        let obj: any = {};
    
        for (let i = 0; i < methodNames.length; i++) {
            obj[methodNames[i]] = jest.fn();
        }
    
        return obj;
    };
    

提交回复
热议问题