This repository was archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathanswer.js
88 lines (78 loc) · 1.91 KB
/
answer.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/// <reference types="cypress" />
/**
* Adds a todo item
* @param {string} text
*/
const addItem = (text) => {
cy.get('.new-todo').type(`${text}{enter}`)
}
describe('reset data using XHR call', () => {
// you can use separate "beforeEach" hooks or a single one
beforeEach(() => {
cy.request('POST', '/reset', {
todos: []
})
})
beforeEach(() => {
cy.visit('/')
})
it('adds two items', () => {
addItem('first item')
addItem('second item')
cy.get('li.todo').should('have.length', 2)
})
})
describe('reset data using cy.writeFile', () => {
beforeEach(() => {
const emptyTodos = {
todos: []
}
const str = JSON.stringify(emptyTodos, null, 2) + '\n'
// file path is relative to the project's root folder
// where cypress.json is located
cy.writeFile('todomvc/data.json', str, 'utf8')
cy.visit('/')
})
it('adds two items', () => {
addItem('first item')
addItem('second item')
cy.get('li.todo').should('have.length', 2)
})
})
describe('reset data using a task', () => {
beforeEach(() => {
cy.task('resetData')
cy.visit('/')
cy.get('li.todo').should('have.length', 0)
})
it('adds two items', () => {
addItem('first item')
addItem('second item')
cy.get('li.todo').should('have.length', 2)
})
})
describe('set initial data', () => {
it('sets data to complex object right away', () => {
cy.task('resetData', {
todos: [
{
id: '123456abc',
completed: true,
title: 'reset data before test'
}
]
})
cy.visit('/')
// check what is rendered
cy.get('li.todo').should('have.length', 1)
})
it('sets data using fixture', () => {
cy.fixture('two-items').then((todos) => {
// "todos" is an array
cy.task('resetData', { todos })
})
cy.visit('/')
// check what is rendered
cy.get('li.todo').should('have.length', 2)
})
})