assertions.ts 562 B

123456789101112131415161718192021
  1. // from https://github.com/cypress-io/cypress/issues/877#issuecomment-538708750
  2. const isInViewport = (_chai) => {
  3. function assertIsInViewport() {
  4. const subject = this._obj;
  5. const bottom = Cypress.config("viewportWidth");
  6. const rect = subject[0].getBoundingClientRect();
  7. this.assert(
  8. rect.top < bottom && rect.bottom < bottom,
  9. "expected #{this} to be in viewport",
  10. "expected #{this} to not be in viewport",
  11. this._obj
  12. )
  13. }
  14. _chai.Assertion.addMethod('inViewport', assertIsInViewport)
  15. };
  16. chai.use(isInViewport);