Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Cypress React Selector to plugin page #2771

Merged
merged 2 commits into from
May 11, 2020

Conversation

abhinaba-ghosh
Copy link
Contributor

Added cypress-react-selector plugin
https://github.com/abhinaba-ghosh/cypress-react-selector

@jennifer-shehane jennifer-shehane requested a review from a team May 4, 2020 04:29
@abhinaba-ghosh
Copy link
Contributor Author

@JessicaSachs @jennifer-shehane Appreciate any feedback.

@bahmutov
Copy link
Contributor

Working in

/// <reference types="cypress" />
import 'cypress-react-selector'
import { mount } from 'cypress-react-unit-test'
import React from 'react'
import ProductsList from './ProductsList.jsx'

// test similar to
// https://github.com/softchris/react-book/blob/7bd767bb39f59977b107d07f383a8f4e32a12857/Testing/test-demo/src/Components/__tests__/ProductsList.js
it('renders without crashing', () => {
  cy.stub(window, 'fetch')
    .withArgs('http://myapi.com/products')
    .resolves({
      json: cy.stub().resolves({
        products: [
          { id: 1, name: 'First item' },
          { id: 2, name: 'Second item' },
        ],
      }),
    })
  mount(<ProductsList />)
  cy.contains('First item').should('be.visible')
  cy.get('.product').should('have.length', 2)

  // use https://github.com/abhinaba-ghosh/cypress-react-selector
  // to find DOM elements by React component constructor name or state
  cy.waitForReact(1000, '#cypress-root')
  cy.react('ProductsContainer').should('have.class', 'product-container')
  cy.react('AProduct').should('have.length', 2)
  cy.react('AProduct', { name: 'Second item' })
    .should('be.visible')
    .and('have.text', 'Second item')
})

The Command Log could be a little better, but since we don't have enough docs for it, it is understandable

Screen Shot 2020-05-11 at 5 24 56 PM

I have opened PR abhinaba-ghosh/cypress-react-selector#9 to improve command log a little bit

Copy link
Contributor

@bahmutov bahmutov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is working and is pretty useful

@bahmutov bahmutov merged commit 718591e into cypress-io:develop May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants