Can we Intercept a line of code similar to api request? #22563
Unanswered
ElamuruganGR
asked this question in
Component Testing
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am trying to mock
window.location.pathname
, I tried many approaches. In thecy.window()
promise only the mock works(insidethen
). But when the testcase calls my actual function wherewindow.location.pathname
is used, its taking the cypress automated browser'spathname
.We use
cy.intercept()
to intercept a request so that whenever cypress encounters a http/https request with the same url,cy.intercept (...)
will run and give the mock response.My question is, Can we use
cy.intercept()
to intercept a single line of code lets say(window.location.pathname==="/") or (let x = a+b)
so that whenever that particular line is executed by calling from the testcase, the mock from incept should be given.Eg:
I always want x to be 10 whenever cypress encounters the above line
I want to mock this line with
let x=10;
I always want execute1() to run whenever cypress encounters the above line
i want to mock this line with
execute1();
Beta Was this translation helpful? Give feedback.
All reactions