/
root.cy.js
124 lines (98 loc) · 2.86 KB
/
root.cy.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const { _ } = Cypress
describe('src/cy/commands/querying', () => {
beforeEach(() => {
cy.visit('/fixtures/dom.html')
})
context('#root', () => {
it('returns html', () => {
const html = cy.$$('html')
cy.root().then(($html) => {
expect($html.get(0)).to.eq(html.get(0))
})
})
it('returns withinSubject if exists', () => {
const form = cy.$$('form')
cy.get('form').first().within(() => {
cy
.get('input')
.root().then(($root) => {
expect($root.get(0)).to.eq(form.get(0))
})
})
})
it('eventually resolves', () => {
_.delay(() => {
cy.$$('html').addClass('foo').addClass('bar')
}
, 100)
cy.root().should('have.class', 'foo').and('have.class', 'bar')
})
// https://github.com/cypress-io/cypress/issues/19985
it('respects timeout option', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.not.contain('4000ms')
done()
})
cy.root({ timeout: 50 }).should('contain', 'root world')
})
describe('.log', () => {
beforeEach(function () {
this.logs = []
cy.on('log:added', (attrs, log) => {
if (attrs.name === 'root') {
this.lastLog = log
this.logs.push(log)
}
})
return null
})
it('can turn off logging', () => {
cy.root({ log: false }).then(function () {
expect(this.log).to.be.undefined
})
})
it('logs immediately before resolving', (done) => {
cy.on('log:added', (attrs, log) => {
if (log.get('name') === 'root') {
expect(log.get('state')).to.eq('pending')
expect(log.get('message')).to.eq('')
done()
}
})
cy.root()
})
it('snapshots after clicking', () => {
cy.root().then(function () {
const { lastLog } = this
expect(lastLog.get('snapshots').length).to.eq(1)
expect(lastLog.get('snapshots')[0]).to.be.an('object')
})
})
it('sets $el to document', () => {
const html = cy.$$('html')
cy.root().then(function () {
expect(this.lastLog.get('$el').get(0)).to.eq(html.get(0))
})
})
it('sets $el to withinSubject', () => {
const form = cy.$$('form')
cy.get('form').first().within(() => {
cy
.get('input')
.root().then(function ($root) {
expect(this.lastLog.get('$el').get(0)).to.eq(form.get(0))
})
})
})
it('consoleProps', () => {
cy.root().then(function ($root) {
const consoleProps = this.lastLog.invoke('consoleProps')
expect(consoleProps).to.deep.eq({
Command: 'root',
Yielded: $root.get(0),
})
})
})
})
})
})