swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

Generated api class is hard to spy on

Open Sczlog opened this issue 1 year ago • 0 comments

Current

In sta, generated Api class is using arrow function image when compile to js, the code will be like this image which has an empty prototype, will unable to modify prototype of Api class for testing or monkey patching.

For example, i am writing unit testing, I am not able to use jest.spyOn(api.prototype,'someApi') as it will throw no property on prototype, but have to mock import to replace entire class import like

const spy = jest.fn()
jest.mock('../path/to/sta',()=>{
    return {
        api: function(){
              return {
                  someApi: spy
              }
        }
    }
})

Expected

Using function expression in class, for example image compiled to image which have a modifiable prototype image

Sczlog avatar Nov 19 '24 03:11 Sczlog