Stubing a class during visiting a page. #30428
Unanswered
Philip-Grozdanov
asked this question in
Questions and Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to stub the return value of a static method of a class(MyCustomClass.ts) after it gets loaded for the first time from visiting a page via
cy.visit(url)
My main page is "index.html". When I visit this page all the typescript files get converted to .js files and then get loaded in the app via GET requests, an example request : "GET", "http://127.0.0.1:9002/services/managers/MyCustomClass.js".
After all the files get loaded fila GET requests the backend calls a class called MainManager.ts (an entry point of the application) which after a number of calls invokes MyCustomClass.myMethod(), my goal
is to stub in that moment the return value of MyCustomClass.myMethod() to be "123" instead of the original one.
From code perspective what happens is :
1.I visit the "index.html"
2.onBeforeLoad runs and stubs the static method
3.all the files load and MainManager gets invoked which prints the original value of MainManager.myMethod() instead of the stubbed "123"
Observations :
This is the order of events from the console:
1.Everwhere in the logs win.customWindowId or window.MyCustomClass returns "mainpageID"
2.From the MainManager.ts the lines which get printed : "===inside init===" and "MyCustomClass myMethod value" , show that
the value is not stubbed and also on the right invoking target is VM198... not a plain class.
Any suggestions how can I achieve this?
Beta Was this translation helpful? Give feedback.
All reactions