You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When cy.xx is called inside a Promise that returns something, no exception is thrown. Instead, the return value is modified to be the return value of the cy.xxx call.
Desired behavior:
I know that we are not allowed to call cy.xxx commands within promises. But it is very confusing to modify the return value instead throwing an exception.
In our case we used cy.log() and were wondering why we receive "undefined".
I would expect an exception to be thrown.
Steps to reproduce:
functionmakeSomething(log: boolean): void{cy.then(()=>Promise.resolve().then(()=>returnTrue(log))).then((val: boolean)=>cy.log(`val is: ${val}`)).wait(5000);}functionreturnTrue(log: boolean): boolean{if(log){cy.log("Test");}returntrue;}describe("Test",()=>{it("test with log",()=>{makeSomething(true);});it("test without log",()=>{makeSomething(false);});});
Output:
test with log
LOG val is: null
test without log
LOG val is: true
Versions
Cypress 3.1.5
Windows 10
Chrome 72.0.3626.109 (Official Build) (64-Bit)
The text was updated successfully, but these errors were encountered:
This is because cy.log() yields null which is what the Promise resolves to. If you changed the cy.log() line to cy.window() - you would see that the yield of the Cypress command (<window>) is being passed on to the next .then().
And yes, this is why we advise against running cypress commands within Promises since commands themselves are promises and it's confusing if you mix Promise chains within Promise chains.
We try to throw a warning in these cases, but I suppose this is an instance where we don't.
Simplified version of what is happening.
it("test with log",()=>{cy.then(()=>{returnPromise.resolve().then(()=>{// THIS LINE IS DIFFERENTcy.log("Test")// enqueued, then runsreturntrue})}).then((val)=>{expect(val).to.be.true})})it("test without log",()=>{cy.then(()=>{returnPromise.resolve().then(()=>{returntrue})}).then((val)=>{expect(val).to.be.true})});
Current behavior:
When cy.xx is called inside a Promise that returns something, no exception is thrown. Instead, the return value is modified to be the return value of the cy.xxx call.
Desired behavior:
I know that we are not allowed to call cy.xxx commands within promises. But it is very confusing to modify the return value instead throwing an exception.
In our case we used
cy.log()
and were wondering why we receive "undefined".I would expect an exception to be thrown.
Steps to reproduce:
Output:
Versions
Cypress 3.1.5
Windows 10
Chrome 72.0.3626.109 (Official Build) (64-Bit)
The text was updated successfully, but these errors were encountered: