docbrown/cypress/support/assertions.js
PJ 800ff397e0
Migrate initializeArticleDate and initializeArticleReactions to Webpack (#19377)
* feat: tests for series list on article page

* feat: test for jump to comments button (needs fix)

* feat: tests for reaction drawer on article page

* feat: test for full date on hover??

* feat: add full date on hover tests for all pages with publish dates

* fixed jumping to comments test

* move initialisers to packs

* fix coverage issues

* fix flaky login modal spec

* switch back to using onclick instead of addEventListener
2023-04-25 18:33:43 +01:00

24 lines
673 B
JavaScript

function assertions(_chai, _utils) {
_chai.Assertion.addMethod('within_viewport', function withinViewport() {
const elements = this._obj;
cy.window().then((window) => {
const viewportRight = window.innerWidth;
const viewportBottom = window.innerHeight;
const bounds = elements[0].getBoundingClientRect();
this.assert(
bounds.top < viewportBottom &&
bounds.bottom > 0 &&
bounds.left < viewportRight &&
bounds.right > 0,
'expected #{this} to be within the viewport',
'expected #{this} to not be within the viewport',
this._obj,
);
});
});
}
chai.use(assertions);