forked from cypress-io/testing-workshop-cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.js
62 lines (55 loc) · 1.65 KB
/
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
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
/// <reference types="cypress" />
// application should be running at port 3000
// and the "localhost:3000" is set as "baseUrl" in "cypress.json"
beforeEach(() => {
cy.request('POST', '/reset', {
todos: []
})
})
beforeEach(() => {
cy.visit('/')
})
/**
* Adds a todo item
* @param {string} text
*/
const addItem = text => {
cy.get('.new-todo').type(`${text}{enter}`)
}
it('adds items to store', () => {
addItem('something')
addItem('something else')
// get application's window
// then get app, $store, state, todos
// it should have 2 items
})
it('creates an item with id 1', () => {
cy.server()
cy.route('POST', '/todos').as('new-item')
// TODO change Math.random to be deterministic
// STEPS
// get the application's "window" object using cy.window
// then change its Math object and replace it
// with your function that always returns "0.1"
addItem('something')
// confirm the item sent to the server has the right values
cy.wait('@new-item').its('request.body').should('deep.equal', {
id: '1',
title: 'something',
completed: false
})
})
// stub function Math.random using cy.stub
it('creates an item with id using a stub', () => {
// get the application's "window.Math" object using cy.window
// replace Math.random with cy.stub and store the stub under an alias
// create a todo using addItem("foo")
// and then confirm that the stub was called once
})
it('puts the todo items into the data store', () => {
// application uses data store to store its items
// you can get the data store using "window.app.$store.state.todos"
// add a couple of items
// get the data store
// check its contents
})