Skip to content

Instantly share code, notes, and snippets.

@cseeger
Forked from xogeny/storybook_spec.js
Last active February 12, 2019 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cseeger/05632ebdd77a57bbff88d57626e84cf0 to your computer and use it in GitHub Desktop.
Save cseeger/05632ebdd77a57bbff88d57626e84cf0 to your computer and use it in GitHub Desktop.
Cypress testing of Storybook
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