Skip to content

Generated api class is hard to spy on #986

@Sczlog

Description

@Sczlog

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions