Reputation: 7633
In this SO post, the following code snippet was posted.
cy.window().then(($window) => {
expect($window.scrollY).to.be.closeTo(400, 100);
});
However, I would like to use the "should" syntax as shown below.
// This code works
cy.window().its('scrollY').should('equal', 400);
How can I use "should" and "closeTo" together in Cypress (the following does not work)?
// This code doesn't work
cy.window().its('scrollY').should('closeTo', 400, 100);
The documentation doesn't seem to show an example for the above case.
Upvotes: 1
Views: 1409
Reputation: 1
This should work.
getScrollContainer().invoke('scrollTop').should('be.closeTo', 10, 100)
Upvotes: 0
Reputation: 7633
Upon closer inspection of the documentation, I believe the following is what I'm after.
cy.window().its('scrollY').should(($scrollY) => {
expect($scrollY).to.be.closeTo(400, 100);
})
Upvotes: 1