Skip to content

Instantly share code, notes, and snippets.

@12
Created August 6, 2019 10:45
Show Gist options
  • Save 12/14507766f572f0713ca06ad54fb0eb03 to your computer and use it in GitHub Desktop.
Save 12/14507766f572f0713ca06ad54fb0eb03 to your computer and use it in GitHub Desktop.
Conditional Cypress
if (service === 'news') {
it('should have a visible image with a caption that is lazyloaded and has a noscript fallback image', () => {
cy.get('figure')
.eq(2)
.within(() => {
cy.get('div div div div').should(
'have.class',
'lazyload-placeholder',
);
})
.scrollIntoView();
cy.get('figure')
.eq(2)
.should('be.visible')
.should('to.have.descendants', 'img')
.should('to.have.descendants', 'figcaption')
// NB: If this test starts failing unexpectedly it's a good sign that the dom is being
// cleared during hydration. React won't render noscript tags on the client so if they
// get cleared during hydration, the following render wont re-add them.
// See https://github.com/facebook/react/issues/11423#issuecomment-341751071 or
// https://github.com/bbc/simorgh/pull/1872 for more infomation.
.within(() => {
cy.get('noscript').contains('<img ');
cy.get('div div').should(
'not.have.class',
'lazyload-placeholder',
);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment