bahmutov / react-loading-skeleton

Create skeleton screens that automatically adapt to your app!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-loading-skeleton

cypress version cypress-react-unit-test version

Forked from dvtng/react-loading-skeleton to show cypress-react-unit-test v2

Toggle test

See stories/Post.cy-spec.js and stories/Skeleton.cy-spec.js

Example test and test video

it('loads title after timeout', () => {
  const Demo = () => {
    // at first there is not title, no children
    const [title, setTitle] = React.useState('');
    const [text, setText] = React.useState('');

    setTimeout(() => {
      setTitle('Post title πŸ‘')
    }, 1000)

    setTimeout(() => {
      setText(`The text has arrived ...
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec
        justo feugiat, auctor nunc ac, volutpat arcu. Suspendisse faucibus
        aliquam ante, sit amet iaculis dolor posuere et. In ut placerat leo.
      `)
    }, 2000)

    return <Post title={title} children={text} />
  }
  mount(<Demo />)
  // at first, the title and the text are πŸ’€
  cy.get('h1 .react-loading-skeleton').should('have.length', 1)
  cy.get('p .react-loading-skeleton').should('have.length', 5)

  // then the title arrives, but the text is still skeletons
  cy.contains('h1', 'Post title πŸ‘').should('be.visible')
  cy.get('p .react-loading-skeleton').should('have.length', 5)

  // and then no skeletons remain
  cy.get('.react-loading-skeleton').should('not.exist')
})

Dynamic test

Note to get component code coverage, run Cypress with BABEL_ENV=test, see .babelrc

About

Create skeleton screens that automatically adapt to your app!

License:MIT License


Languages

Language:JavaScript 99.8%Language:CSS 0.2%