This repository was archived by the owner on Mar 5, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 11 files changed +139
-0
lines changed
cypress/component/component tests/basic/react-tutorial Expand file tree Collapse file tree 11 files changed +139
-0
lines changed Original file line number Diff line number Diff line change 1+ Examples from https://reactjs.org/tutorial/tutorial.html
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ import ShoppingList from './shopping-list.jsx'
3+ import React from 'react'
4+ import { mount } from 'cypress-react-unit-tests'
5+
6+ describe ( 'Shopping list' , ( ) => {
7+ beforeEach ( ( ) => {
8+ cy . viewport ( 600 , 400 )
9+ } )
10+ it ( 'renders' , ( ) => {
11+ mount ( < ShoppingList name = "Mark" /> )
12+ cy . contains ( 'h1' , 'Mark' )
13+ } )
14+ } )
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ export default class ShoppingList extends React . Component {
3+ render ( ) {
4+ return (
5+ < div className = "shopping-list" >
6+ < h1 > Shopping List for { this . props . name } </ h1 >
7+ < ul >
8+ < li > Instagram</ li >
9+ < li > WhatsApp</ li >
10+ < li > Oculus</ li >
11+ </ ul >
12+ </ div >
13+ )
14+ }
15+ }
16+
17+ // Example usage: <ShoppingList name="Mark" />
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ import Square from './square1.jsx'
3+ import React from 'react'
4+ import { mount } from 'cypress-react-unit-tests'
5+
6+ it ( 'renders' , ( ) => {
7+ mount ( < Square /> )
8+ cy . on ( 'window:alert' , cy . stub ( ) . as ( 'alerted' ) )
9+ cy . get ( '.square' ) . click ( )
10+ cy . get ( '@alerted' )
11+ . should ( 'have.been.calledOnce' )
12+ . and ( 'have.been.calledWithExactly' , 'click' )
13+ } )
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ export default class Square extends React . Component {
3+ render ( ) {
4+ return (
5+ < button className = "square" onClick = { ( ) => alert ( 'click' ) } >
6+ { this . props . value }
7+ </ button >
8+ )
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ import Square from './square2.jsx'
3+ import React from 'react'
4+ import { mount } from 'cypress-react-unit-tests'
5+
6+ it ( 'renders' , ( ) => {
7+ mount ( < Square value = "X" /> )
8+ cy . on ( 'window:alert' , cy . stub ( ) . as ( 'alerted' ) )
9+ cy . get ( '.square' )
10+ . should ( 'have.text' , 'X' )
11+ . click ( )
12+ cy . get ( '@alerted' )
13+ . should ( 'have.been.calledOnce' )
14+ . and ( 'have.been.calledWithExactly' , 'click' )
15+ } )
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ export default class Square extends React . Component {
3+ constructor ( props ) {
4+ super ( props )
5+ this . state = {
6+ value : null ,
7+ }
8+ }
9+
10+ render ( ) {
11+ return (
12+ < button className = "square" onClick = { ( ) => alert ( 'click' ) } >
13+ { this . props . value }
14+ </ button >
15+ )
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ import Square from './square3.jsx'
3+ import React from 'react'
4+ import { mount } from 'cypress-react-unit-tests'
5+
6+ it ( 'renders' , ( ) => {
7+ mount ( < Square /> )
8+ cy . get ( '.square' )
9+ . should ( 'have.text' , '' )
10+ . click ( )
11+ cy . contains ( '.square' , 'X' )
12+ } )
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ export default class Square extends React . Component {
3+ constructor ( props ) {
4+ super ( props )
5+ this . state = {
6+ value : null ,
7+ }
8+ }
9+
10+ render ( ) {
11+ return (
12+ < button className = "square" onClick = { ( ) => this . setState ( { value : 'X' } ) } >
13+ { this . state . value }
14+ </ button >
15+ )
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ import Square from './square4.jsx'
3+ import React from 'react'
4+ import { mount } from 'cypress-react-unit-tests'
5+
6+ it ( 'renders' , ( ) => {
7+ const onClick = cy . stub ( )
8+ mount ( < Square value = "O" onClick = { onClick } /> )
9+ cy . get ( '.square' )
10+ . should ( 'have.text' , 'O' )
11+ . click ( )
12+ . then ( ( ) => {
13+ expect ( onClick ) . to . have . been . calledOnce
14+ } )
15+ } )
You can’t perform that action at this time.
0 commit comments