-
-
Save cseeger/05632ebdd77a57bbff88d57626e84cf0 to your computer and use it in GitHub Desktop.
Cypress testing of Storybook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Storybook', () => { | |
beforeEach(() => { | |
cy.visit('http://airbnb.io/react-dates/') | |
}) | |
context('DateRangePicker', () => { | |
it('should visit the default story in this collection', () => { | |
cy.get('a[data-name="default"]').click() | |
// Get the iframe for the components and make assertions on that. | |
cy.get('#storybook-preview-iframe').then(($iframe) => { | |
const doc = $iframe.contents(); | |
iget(doc, "#startDate").click(); | |
iget(doc, "#root > div > div:nth-child(2) > div > a").should('have.text', "Show Info"); | |
}) | |
}) | |
}) | |
context("DayPicker", () => { | |
beforeEach(() => { | |
cy.get('div[data-name="DayPicker"]').click(); | |
}) | |
it('should visit the vertical day picker', () => { | |
cy.get('a[data-name="vertical"]').click(); | |
// Get the iframe for the components and make assertions on that. | |
cy.get('#storybook-preview-iframe').then(($iframe) => { | |
const doc = $iframe.contents(); | |
// This is an implicit assertion that this element exists | |
iget(doc, 'div[aria-label="Calendar"]'); | |
}) | |
}) | |
}) | |
}) | |
// Helper func to access Storybook "showcase" iframe | |
function iget(doc, selector) { | |
return cy.wrap(doc.find(selector)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment