forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtic-tac-toe-spec.js
34 lines (30 loc) · 976 Bytes
/
tic-tac-toe-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// entire game from the tutorial inside the spec for simplicity
// the code taken from https://codepen.io/gaearon/pen/LyyXgK
/// <reference types="cypress" />
import React from 'react'
import { mount } from 'cypress-react-unit-test'
import { Game } from './tic-tac-toe.jsx'
describe('Tic Tac Toe', () => {
/**
* Clicks on a square, give
* @param {number} row 0 based
* @param {number} column 0 based
*/
const clickSquare = (row, column) => cy.get('.square').eq(row * 3 + column)
beforeEach(() => {
cy.viewport(200, 200)
})
it('starts and lets X win', () => {
mount(<Game />, {
cssFile: 'cypress/component/advanced/tutorial/tic-tac-toe.css',
})
cy.contains('.status', 'Next player: X')
clickSquare(0, 0).click()
cy.contains('.status', 'Next player: O')
clickSquare(0, 1).click()
clickSquare(1, 0).click()
clickSquare(1, 1).click()
clickSquare(2, 0).click()
cy.contains('.status', 'Winner: X')
})
})