Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated api class is hard to spy on #986

Open
Sczlog opened this issue Nov 19, 2024 · 0 comments
Open

Generated api class is hard to spy on #986

Sczlog opened this issue Nov 19, 2024 · 0 comments

Comments

@Sczlog
Copy link

Sczlog commented Nov 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant