This repository has been archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathanswer.js
70 lines (61 loc) · 1.62 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
/// <reference types="cypress" />
/// <reference path="./custom-commands.d.ts" />
require('cypress-pipe')
import { resetData, visitSite } from '../../support/utils'
beforeEach(resetData)
beforeEach(visitSite)
it('enters 10 todos', function () {
cy.get('.new-todo')
.type('todo 0{enter}')
.type('todo 1{enter}')
.type('todo 2{enter}')
.type('todo 3{enter}')
.type('todo 4{enter}')
.type('todo 5{enter}')
.type('todo 6{enter}')
.type('todo 7{enter}')
.type('todo 8{enter}')
.type('todo 9{enter}')
cy.get('.todo').should('have.length', 10)
})
// simple custom command
Cypress.Commands.add('createTodo', (todo) => {
cy.get('.new-todo').type(`${todo}{enter}`)
})
// with better command log
Cypress.Commands.add('createTodo', (todo) => {
cy.get('.new-todo', { log: false }).type(`${todo}{enter}`, { log: false })
cy.log('createTodo', todo)
})
// with full command log
Cypress.Commands.add('createTodo', (todo) => {
const cmd = Cypress.log({
name: 'create todo',
message: todo,
consoleProps() {
return {
'Create Todo': todo
}
}
})
cy.get('.new-todo', { log: false })
.type(`${todo}{enter}`, { log: false })
.then(($el) => {
cmd.set({ $el }).snapshot().end()
})
})
it('creates a todo', () => {
cy.createTodo('my first todo')
})
it('passes when object gets new property', () => {
const o = {}
setTimeout(() => {
o.foo = 'bar'
}, 1000)
const get = (name) =>
function getProp(from) {
console.log('getting', from)
return from[name]
}
cy.wrap(o).pipe(get('foo')).should('not.be.undefined').and('equal', 'bar')
})