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 pathspec.js
71 lines (63 loc) · 1.95 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
63
64
65
66
67
68
69
70
71
/// <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
})
it('handles todos with blank title', () => {
// bypass the UI and call app's actions directly from the test
// app.$store.dispatch('setNewTodo', <desired text>)
// app.$store.dispatch('addTodo')
// using https://on.cypress.io/invoke
// and then
// confirm the application is not breaking
})