eslint-plugin-cypress 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/circle.yml +82 -9
  2. package/eslint.config.mjs +1 -0
  3. package/package.json +6 -6
  4. package/test-project/README.md +48 -0
  5. package/test-project/cypress/e2e/1-getting-started/todo.cy.js +143 -0
  6. package/test-project/cypress/e2e/2-advanced-examples/actions.cy.js +321 -0
  7. package/test-project/cypress/e2e/2-advanced-examples/aliasing.cy.js +39 -0
  8. package/test-project/cypress/e2e/2-advanced-examples/assertions.cy.js +176 -0
  9. package/test-project/cypress/e2e/2-advanced-examples/connectors.cy.js +98 -0
  10. package/test-project/cypress/e2e/2-advanced-examples/cookies.cy.js +118 -0
  11. package/test-project/cypress/e2e/2-advanced-examples/cypress_api.cy.js +185 -0
  12. package/test-project/cypress/e2e/2-advanced-examples/files.cy.js +85 -0
  13. package/test-project/cypress/e2e/2-advanced-examples/location.cy.js +32 -0
  14. package/test-project/cypress/e2e/2-advanced-examples/misc.cy.js +90 -0
  15. package/test-project/cypress/e2e/2-advanced-examples/navigation.cy.js +55 -0
  16. package/test-project/cypress/e2e/2-advanced-examples/network_requests.cy.js +163 -0
  17. package/test-project/cypress/e2e/2-advanced-examples/querying.cy.js +114 -0
  18. package/test-project/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +204 -0
  19. package/test-project/cypress/e2e/2-advanced-examples/storage.cy.js +117 -0
  20. package/test-project/cypress/e2e/2-advanced-examples/traversal.cy.js +121 -0
  21. package/test-project/cypress/e2e/2-advanced-examples/utilities.cy.js +107 -0
  22. package/test-project/cypress/e2e/2-advanced-examples/viewport.cy.js +58 -0
  23. package/test-project/cypress/e2e/2-advanced-examples/waiting.cy.js +30 -0
  24. package/test-project/cypress/e2e/2-advanced-examples/window.cy.js +22 -0
  25. package/test-project/cypress/fixtures/example.json +5 -0
  26. package/test-project/cypress/support/commands.js +25 -0
  27. package/test-project/cypress/support/e2e.js +17 -0
  28. package/test-project/cypress.config.js +9 -0
  29. package/test-project/eslint-configs/eslint.default.mjs +9 -0
  30. package/test-project/eslint-configs/eslint.globals.mjs +4 -0
  31. package/test-project/eslint-configs/eslint.recommended.mjs +9 -0
  32. package/test-project/eslint.config.mjs +9 -0
  33. package/test-project/package.json +9 -0
@@ -0,0 +1,204 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Spies, Stubs, and Clock', () => {
4
+ it('cy.spy() - wrap a method in a spy', () => {
5
+ // https://on.cypress.io/spy
6
+ cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
7
+
8
+ const obj = {
9
+ foo () {},
10
+ }
11
+
12
+ const spy = cy.spy(obj, 'foo').as('anyArgs')
13
+
14
+ obj.foo()
15
+
16
+ expect(spy).to.be.called
17
+ })
18
+
19
+ it('cy.spy() retries until assertions pass', () => {
20
+ cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
21
+
22
+ const obj = {
23
+ /**
24
+ * Prints the argument passed
25
+ * @param x {any}
26
+ */
27
+ foo (x) {
28
+ console.log('obj.foo called with', x)
29
+ },
30
+ }
31
+
32
+ cy.spy(obj, 'foo').as('foo')
33
+
34
+ setTimeout(() => {
35
+ obj.foo('first')
36
+ }, 500)
37
+
38
+ setTimeout(() => {
39
+ obj.foo('second')
40
+ }, 2500)
41
+
42
+ cy.get('@foo').should('have.been.calledTwice')
43
+ })
44
+
45
+ it('cy.stub() - create a stub and/or replace a function with stub', () => {
46
+ // https://on.cypress.io/stub
47
+ cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
48
+
49
+ const obj = {
50
+ /**
51
+ * prints both arguments to the console
52
+ * @param a {string}
53
+ * @param b {string}
54
+ */
55
+ foo (a, b) {
56
+ console.log('a', a, 'b', b)
57
+ },
58
+ }
59
+
60
+ const stub = cy.stub(obj, 'foo').as('foo')
61
+
62
+ obj.foo('foo', 'bar')
63
+
64
+ expect(stub).to.be.called
65
+ })
66
+
67
+ it('cy.clock() - control time in the browser', () => {
68
+ // https://on.cypress.io/clock
69
+
70
+ // create the date in UTC so it's always the same
71
+ // no matter what local timezone the browser is running in
72
+ const now = new Date(Date.UTC(2017, 2, 14)).getTime()
73
+
74
+ cy.clock(now)
75
+ cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
76
+ cy.get('#clock-div').click()
77
+ cy.get('#clock-div')
78
+ .should('have.text', '1489449600')
79
+ })
80
+
81
+ it('cy.tick() - move time in the browser', () => {
82
+ // https://on.cypress.io/tick
83
+
84
+ // create the date in UTC so it's always the same
85
+ // no matter what local timezone the browser is running in
86
+ const now = new Date(Date.UTC(2017, 2, 14)).getTime()
87
+
88
+ cy.clock(now)
89
+ cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
90
+ cy.get('#tick-div').click()
91
+ cy.get('#tick-div')
92
+ .should('have.text', '1489449600')
93
+
94
+ cy.tick(10000) // 10 seconds passed
95
+ cy.get('#tick-div').click()
96
+ cy.get('#tick-div')
97
+ .should('have.text', '1489449610')
98
+ })
99
+
100
+ it('cy.stub() matches depending on arguments', () => {
101
+ // see all possible matchers at
102
+ // https://sinonjs.org/releases/latest/matchers/
103
+ const greeter = {
104
+ /**
105
+ * Greets a person
106
+ * @param {string} name
107
+ */
108
+ greet (name) {
109
+ return `Hello, ${name}!`
110
+ },
111
+ }
112
+
113
+ cy.stub(greeter, 'greet')
114
+ .callThrough() // if you want non-matched calls to call the real method
115
+ .withArgs(Cypress.sinon.match.string).returns('Hi')
116
+ .withArgs(Cypress.sinon.match.number).throws(new Error('Invalid name'))
117
+
118
+ expect(greeter.greet('World')).to.equal('Hi')
119
+ expect(() => greeter.greet(42)).to.throw('Invalid name')
120
+ expect(greeter.greet).to.have.been.calledTwice
121
+
122
+ // non-matched calls goes the actual method
123
+ expect(greeter.greet()).to.equal('Hello, undefined!')
124
+ })
125
+
126
+ it('matches call arguments using Sinon matchers', () => {
127
+ // see all possible matchers at
128
+ // https://sinonjs.org/releases/latest/matchers/
129
+ const calculator = {
130
+ /**
131
+ * returns the sum of two arguments
132
+ * @param a {number}
133
+ * @param b {number}
134
+ */
135
+ add (a, b) {
136
+ return a + b
137
+ },
138
+ }
139
+
140
+ const spy = cy.spy(calculator, 'add').as('add')
141
+
142
+ expect(calculator.add(2, 3)).to.equal(5)
143
+
144
+ // if we want to assert the exact values used during the call
145
+ expect(spy).to.be.calledWith(2, 3)
146
+
147
+ // let's confirm "add" method was called with two numbers
148
+ expect(spy).to.be.calledWith(Cypress.sinon.match.number, Cypress.sinon.match.number)
149
+
150
+ // alternatively, provide the value to match
151
+ expect(spy).to.be.calledWith(Cypress.sinon.match(2), Cypress.sinon.match(3))
152
+
153
+ // match any value
154
+ expect(spy).to.be.calledWith(Cypress.sinon.match.any, 3)
155
+
156
+ // match any value from a list
157
+ expect(spy).to.be.calledWith(Cypress.sinon.match.in([1, 2, 3]), 3)
158
+
159
+ /**
160
+ * Returns true if the given number is even
161
+ * @param {number} x
162
+ */
163
+ const isEven = (x) => x % 2 === 0
164
+
165
+ // expect the value to pass a custom predicate function
166
+ // the second argument to "sinon.match(predicate, message)" is
167
+ // shown if the predicate does not pass and assertion fails
168
+ expect(spy).to.be.calledWith(Cypress.sinon.match(isEven, 'isEven'), 3)
169
+
170
+ /**
171
+ * Returns a function that checks if a given number is larger than the limit
172
+ * @param {number} limit
173
+ * @returns {(x: number) => boolean}
174
+ */
175
+ const isGreaterThan = (limit) => (x) => x > limit
176
+
177
+ /**
178
+ * Returns a function that checks if a given number is less than the limit
179
+ * @param {number} limit
180
+ * @returns {(x: number) => boolean}
181
+ */
182
+ const isLessThan = (limit) => (x) => x < limit
183
+
184
+ // you can combine several matchers using "and", "or"
185
+ expect(spy).to.be.calledWith(
186
+ Cypress.sinon.match.number,
187
+ Cypress.sinon.match(isGreaterThan(2), '> 2').and(Cypress.sinon.match(isLessThan(4), '< 4')),
188
+ )
189
+
190
+ expect(spy).to.be.calledWith(
191
+ Cypress.sinon.match.number,
192
+ Cypress.sinon.match(isGreaterThan(200), '> 200').or(Cypress.sinon.match(3)),
193
+ )
194
+
195
+ // matchers can be used from BDD assertions
196
+ cy.get('@add').should('have.been.calledWith',
197
+ Cypress.sinon.match.number, Cypress.sinon.match(3))
198
+
199
+ // you can alias matchers for shorter test code
200
+ const { match: M } = Cypress.sinon
201
+
202
+ cy.get('@add').should('have.been.calledWith', M.number, M(3))
203
+ })
204
+ })
@@ -0,0 +1,117 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Local Storage / Session Storage', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/storage')
6
+ })
7
+ // Although localStorage is automatically cleared
8
+ // in between tests to maintain a clean state
9
+ // sometimes we need to clear localStorage manually
10
+
11
+ it('cy.clearLocalStorage() - clear all data in localStorage for the current origin', () => {
12
+ // https://on.cypress.io/clearlocalstorage
13
+ cy.get('.ls-btn').click()
14
+ cy.get('.ls-btn').should(() => {
15
+ expect(localStorage.getItem('prop1')).to.eq('red')
16
+ expect(localStorage.getItem('prop2')).to.eq('blue')
17
+ expect(localStorage.getItem('prop3')).to.eq('magenta')
18
+ })
19
+
20
+ cy.clearLocalStorage()
21
+ cy.getAllLocalStorage().should(() => {
22
+ expect(localStorage.getItem('prop1')).to.be.null
23
+ expect(localStorage.getItem('prop2')).to.be.null
24
+ expect(localStorage.getItem('prop3')).to.be.null
25
+ })
26
+
27
+ cy.get('.ls-btn').click()
28
+ cy.get('.ls-btn').should(() => {
29
+ expect(localStorage.getItem('prop1')).to.eq('red')
30
+ expect(localStorage.getItem('prop2')).to.eq('blue')
31
+ expect(localStorage.getItem('prop3')).to.eq('magenta')
32
+ })
33
+
34
+ // Clear key matching string in localStorage
35
+ cy.clearLocalStorage('prop1')
36
+ cy.getAllLocalStorage().should(() => {
37
+ expect(localStorage.getItem('prop1')).to.be.null
38
+ expect(localStorage.getItem('prop2')).to.eq('blue')
39
+ expect(localStorage.getItem('prop3')).to.eq('magenta')
40
+ })
41
+
42
+ cy.get('.ls-btn').click()
43
+ cy.get('.ls-btn').should(() => {
44
+ expect(localStorage.getItem('prop1')).to.eq('red')
45
+ expect(localStorage.getItem('prop2')).to.eq('blue')
46
+ expect(localStorage.getItem('prop3')).to.eq('magenta')
47
+ })
48
+
49
+ // Clear keys matching regex in localStorage
50
+ cy.clearLocalStorage(/prop1|2/)
51
+ cy.getAllLocalStorage().should(() => {
52
+ expect(localStorage.getItem('prop1')).to.be.null
53
+ expect(localStorage.getItem('prop2')).to.be.null
54
+ expect(localStorage.getItem('prop3')).to.eq('magenta')
55
+ })
56
+ })
57
+
58
+ it('cy.getAllLocalStorage() - get all data in localStorage for all origins', () => {
59
+ // https://on.cypress.io/getalllocalstorage
60
+ cy.get('.ls-btn').click()
61
+
62
+ // getAllLocalStorage() yields a map of origins to localStorage values
63
+ cy.getAllLocalStorage().should((storageMap) => {
64
+ expect(storageMap).to.deep.equal({
65
+ // other origins will also be present if localStorage is set on them
66
+ 'https://example.cypress.io': {
67
+ 'prop1': 'red',
68
+ 'prop2': 'blue',
69
+ 'prop3': 'magenta',
70
+ },
71
+ })
72
+ })
73
+ })
74
+
75
+ it('cy.clearAllLocalStorage() - clear all data in localStorage for all origins', () => {
76
+ // https://on.cypress.io/clearalllocalstorage
77
+ cy.get('.ls-btn').click()
78
+
79
+ // clearAllLocalStorage() yields null
80
+ cy.clearAllLocalStorage()
81
+ cy.getAllLocalStorage().should(() => {
82
+ expect(localStorage.getItem('prop1')).to.be.null
83
+ expect(localStorage.getItem('prop2')).to.be.null
84
+ expect(localStorage.getItem('prop3')).to.be.null
85
+ })
86
+ })
87
+
88
+ it('cy.getAllSessionStorage() - get all data in sessionStorage for all origins', () => {
89
+ // https://on.cypress.io/getallsessionstorage
90
+ cy.get('.ls-btn').click()
91
+
92
+ // getAllSessionStorage() yields a map of origins to sessionStorage values
93
+ cy.getAllSessionStorage().should((storageMap) => {
94
+ expect(storageMap).to.deep.equal({
95
+ // other origins will also be present if sessionStorage is set on them
96
+ 'https://example.cypress.io': {
97
+ 'prop4': 'cyan',
98
+ 'prop5': 'yellow',
99
+ 'prop6': 'black',
100
+ },
101
+ })
102
+ })
103
+ })
104
+
105
+ it('cy.clearAllSessionStorage() - clear all data in sessionStorage for all origins', () => {
106
+ // https://on.cypress.io/clearallsessionstorage
107
+ cy.get('.ls-btn').click()
108
+
109
+ // clearAllSessionStorage() yields null
110
+ cy.clearAllSessionStorage()
111
+ cy.getAllSessionStorage().should(() => {
112
+ expect(sessionStorage.getItem('prop4')).to.be.null
113
+ expect(sessionStorage.getItem('prop5')).to.be.null
114
+ expect(sessionStorage.getItem('prop6')).to.be.null
115
+ })
116
+ })
117
+ })
@@ -0,0 +1,121 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Traversal', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/traversal')
6
+ })
7
+
8
+ it('.children() - get child DOM elements', () => {
9
+ // https://on.cypress.io/children
10
+ cy.get('.traversal-breadcrumb')
11
+ .children('.active')
12
+ .should('contain', 'Data')
13
+ })
14
+
15
+ it('.closest() - get closest ancestor DOM element', () => {
16
+ // https://on.cypress.io/closest
17
+ cy.get('.traversal-badge')
18
+ .closest('ul')
19
+ .should('have.class', 'list-group')
20
+ })
21
+
22
+ it('.eq() - get a DOM element at a specific index', () => {
23
+ // https://on.cypress.io/eq
24
+ cy.get('.traversal-list>li')
25
+ .eq(1).should('contain', 'siamese')
26
+ })
27
+
28
+ it('.filter() - get DOM elements that match the selector', () => {
29
+ // https://on.cypress.io/filter
30
+ cy.get('.traversal-nav>li')
31
+ .filter('.active').should('contain', 'About')
32
+ })
33
+
34
+ it('.find() - get descendant DOM elements of the selector', () => {
35
+ // https://on.cypress.io/find
36
+ cy.get('.traversal-pagination')
37
+ .find('li').find('a')
38
+ .should('have.length', 7)
39
+ })
40
+
41
+ it('.first() - get first DOM element', () => {
42
+ // https://on.cypress.io/first
43
+ cy.get('.traversal-table td')
44
+ .first().should('contain', '1')
45
+ })
46
+
47
+ it('.last() - get last DOM element', () => {
48
+ // https://on.cypress.io/last
49
+ cy.get('.traversal-buttons .btn')
50
+ .last().should('contain', 'Submit')
51
+ })
52
+
53
+ it('.next() - get next sibling DOM element', () => {
54
+ // https://on.cypress.io/next
55
+ cy.get('.traversal-ul')
56
+ .contains('apples').next().should('contain', 'oranges')
57
+ })
58
+
59
+ it('.nextAll() - get all next sibling DOM elements', () => {
60
+ // https://on.cypress.io/nextall
61
+ cy.get('.traversal-next-all')
62
+ .contains('oranges')
63
+ .nextAll().should('have.length', 3)
64
+ })
65
+
66
+ it('.nextUntil() - get next sibling DOM elements until next el', () => {
67
+ // https://on.cypress.io/nextuntil
68
+ cy.get('#veggies')
69
+ .nextUntil('#nuts').should('have.length', 3)
70
+ })
71
+
72
+ it('.not() - remove DOM elements from set of DOM elements', () => {
73
+ // https://on.cypress.io/not
74
+ cy.get('.traversal-disabled .btn')
75
+ .not('[disabled]').should('not.contain', 'Disabled')
76
+ })
77
+
78
+ it('.parent() - get parent DOM element from DOM elements', () => {
79
+ // https://on.cypress.io/parent
80
+ cy.get('.traversal-mark')
81
+ .parent().should('contain', 'Morbi leo risus')
82
+ })
83
+
84
+ it('.parents() - get parent DOM elements from DOM elements', () => {
85
+ // https://on.cypress.io/parents
86
+ cy.get('.traversal-cite')
87
+ .parents().should('match', 'blockquote')
88
+ })
89
+
90
+ it('.parentsUntil() - get parent DOM elements from DOM elements until el', () => {
91
+ // https://on.cypress.io/parentsuntil
92
+ cy.get('.clothes-nav')
93
+ .find('.active')
94
+ .parentsUntil('.clothes-nav')
95
+ .should('have.length', 2)
96
+ })
97
+
98
+ it('.prev() - get previous sibling DOM element', () => {
99
+ // https://on.cypress.io/prev
100
+ cy.get('.birds').find('.active')
101
+ .prev().should('contain', 'Lorikeets')
102
+ })
103
+
104
+ it('.prevAll() - get all previous sibling DOM elements', () => {
105
+ // https://on.cypress.io/prevall
106
+ cy.get('.fruits-list').find('.third')
107
+ .prevAll().should('have.length', 2)
108
+ })
109
+
110
+ it('.prevUntil() - get all previous sibling DOM elements until el', () => {
111
+ // https://on.cypress.io/prevuntil
112
+ cy.get('.foods-list').find('#nuts')
113
+ .prevUntil('#veggies').should('have.length', 3)
114
+ })
115
+
116
+ it('.siblings() - get all sibling DOM elements', () => {
117
+ // https://on.cypress.io/siblings
118
+ cy.get('.traversal-pills .active')
119
+ .siblings().should('have.length', 2)
120
+ })
121
+ })
@@ -0,0 +1,107 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Utilities', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/utilities')
6
+ })
7
+
8
+ it('Cypress._ - call a lodash method', () => {
9
+ // https://on.cypress.io/_
10
+ cy.request('https://jsonplaceholder.cypress.io/users')
11
+ .then((response) => {
12
+ let ids = Cypress._.chain(response.body).map('id').take(3).value()
13
+
14
+ expect(ids).to.deep.eq([1, 2, 3])
15
+ })
16
+ })
17
+
18
+ it('Cypress.$ - call a jQuery method', () => {
19
+ // https://on.cypress.io/$
20
+ let $li = Cypress.$('.utility-jquery li:first')
21
+
22
+ cy.wrap($li).should('not.have.class', 'active')
23
+ cy.wrap($li).click()
24
+ cy.wrap($li).should('have.class', 'active')
25
+ })
26
+
27
+ it('Cypress.Blob - blob utilities and base64 string conversion', () => {
28
+ // https://on.cypress.io/blob
29
+ cy.get('.utility-blob').then(($div) => {
30
+ // https://github.com/nolanlawson/blob-util#imgSrcToDataURL
31
+ // get the dataUrl string for the javascript-logo
32
+ return Cypress.Blob.imgSrcToDataURL('https://example.cypress.io/assets/img/javascript-logo.png', undefined, 'anonymous')
33
+ .then((dataUrl) => {
34
+ // create an <img> element and set its src to the dataUrl
35
+ let img = Cypress.$('<img />', { src: dataUrl })
36
+
37
+ // need to explicitly return cy here since we are initially returning
38
+ // the Cypress.Blob.imgSrcToDataURL promise to our test
39
+ // append the image
40
+ $div.append(img)
41
+
42
+ cy.get('.utility-blob img').click()
43
+ cy.get('.utility-blob img').should('have.attr', 'src', dataUrl)
44
+ })
45
+ })
46
+ })
47
+
48
+ it('Cypress.minimatch - test out glob patterns against strings', () => {
49
+ // https://on.cypress.io/minimatch
50
+ let matching = Cypress.minimatch('/users/1/comments', '/users/*/comments', {
51
+ matchBase: true,
52
+ })
53
+
54
+ expect(matching, 'matching wildcard').to.be.true
55
+
56
+ matching = Cypress.minimatch('/users/1/comments/2', '/users/*/comments', {
57
+ matchBase: true,
58
+ })
59
+
60
+ expect(matching, 'comments').to.be.false
61
+
62
+ // ** matches against all downstream path segments
63
+ matching = Cypress.minimatch('/foo/bar/baz/123/quux?a=b&c=2', '/foo/**', {
64
+ matchBase: true,
65
+ })
66
+
67
+ expect(matching, 'comments').to.be.true
68
+
69
+ // whereas * matches only the next path segment
70
+
71
+ matching = Cypress.minimatch('/foo/bar/baz/123/quux?a=b&c=2', '/foo/*', {
72
+ matchBase: false,
73
+ })
74
+
75
+ expect(matching, 'comments').to.be.false
76
+ })
77
+
78
+ it('Cypress.Promise - instantiate a bluebird promise', () => {
79
+ // https://on.cypress.io/promise
80
+ let waited = false
81
+
82
+ /**
83
+ * @return Bluebird<string>
84
+ */
85
+ function waitOneSecond () {
86
+ // return a promise that resolves after 1 second
87
+ return new Cypress.Promise((resolve, reject) => {
88
+ setTimeout(() => {
89
+ // set waited to true
90
+ waited = true
91
+
92
+ // resolve with 'foo' string
93
+ resolve('foo')
94
+ }, 1000)
95
+ })
96
+ }
97
+
98
+ cy.then(() => {
99
+ // return a promise to cy.then() that
100
+ // is awaited until it resolves
101
+ return waitOneSecond().then((str) => {
102
+ expect(str).to.eq('foo')
103
+ expect(waited).to.be.true
104
+ })
105
+ })
106
+ })
107
+ })
@@ -0,0 +1,58 @@
1
+ /// <reference types="cypress" />
2
+ context('Viewport', () => {
3
+ beforeEach(() => {
4
+ cy.visit('https://example.cypress.io/commands/viewport')
5
+ })
6
+
7
+ it('cy.viewport() - set the viewport size and dimension', () => {
8
+ // https://on.cypress.io/viewport
9
+
10
+ cy.get('#navbar').should('be.visible')
11
+ cy.viewport(320, 480)
12
+
13
+ // the navbar should have collapse since our screen is smaller
14
+ cy.get('#navbar').should('not.be.visible')
15
+ cy.get('.navbar-toggle').should('be.visible').click()
16
+ cy.get('.nav').find('a').should('be.visible')
17
+
18
+ // lets see what our app looks like on a super large screen
19
+ cy.viewport(2999, 2999)
20
+
21
+ // cy.viewport() accepts a set of preset sizes
22
+ // to easily set the screen to a device's width and height
23
+
24
+ // We added a cy.wait() between each viewport change so you can see
25
+ // the change otherwise it is a little too fast to see :)
26
+
27
+ cy.viewport('macbook-15')
28
+ cy.wait(200)
29
+ cy.viewport('macbook-13')
30
+ cy.wait(200)
31
+ cy.viewport('macbook-11')
32
+ cy.wait(200)
33
+ cy.viewport('ipad-2')
34
+ cy.wait(200)
35
+ cy.viewport('ipad-mini')
36
+ cy.wait(200)
37
+ cy.viewport('iphone-6+')
38
+ cy.wait(200)
39
+ cy.viewport('iphone-6')
40
+ cy.wait(200)
41
+ cy.viewport('iphone-5')
42
+ cy.wait(200)
43
+ cy.viewport('iphone-4')
44
+ cy.wait(200)
45
+ cy.viewport('iphone-3')
46
+ cy.wait(200)
47
+
48
+ // cy.viewport() accepts an orientation for all presets
49
+ // the default orientation is 'portrait'
50
+ cy.viewport('ipad-2', 'portrait')
51
+ cy.wait(200)
52
+ cy.viewport('iphone-4', 'landscape')
53
+ cy.wait(200)
54
+
55
+ // The viewport will be reset back to the default dimensions
56
+ // in between tests (the default can be set in cypress.config.{js|ts})
57
+ })
58
+ })
@@ -0,0 +1,30 @@
1
+ /// <reference types="cypress" />
2
+ context('Waiting', () => {
3
+ beforeEach(() => {
4
+ cy.visit('https://example.cypress.io/commands/waiting')
5
+ })
6
+ // BE CAREFUL of adding unnecessary wait times.
7
+ // https://on.cypress.io/best-practices#Unnecessary-Waiting
8
+
9
+ // https://on.cypress.io/wait
10
+ it('cy.wait() - wait for a specific amount of time', () => {
11
+ cy.get('.wait-input1').type('Wait 1000ms after typing')
12
+ cy.wait(1000)
13
+ cy.get('.wait-input2').type('Wait 1000ms after typing')
14
+ cy.wait(1000)
15
+ cy.get('.wait-input3').type('Wait 1000ms after typing')
16
+ cy.wait(1000)
17
+ })
18
+
19
+ it('cy.wait() - wait for a specific route', () => {
20
+ // Listen to GET to comments/1
21
+ cy.intercept('GET', '**/comments/*').as('getComment')
22
+
23
+ // we have code that gets a comment when
24
+ // the button is clicked in scripts.js
25
+ cy.get('.network-btn').click()
26
+
27
+ // wait for GET comments/1
28
+ cy.wait('@getComment').its('response.statusCode').should('be.oneOf', [200, 304])
29
+ })
30
+ })
@@ -0,0 +1,22 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Window', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/window')
6
+ })
7
+
8
+ it('cy.window() - get the global window object', () => {
9
+ // https://on.cypress.io/window
10
+ cy.window().should('have.property', 'top')
11
+ })
12
+
13
+ it('cy.document() - get the document object', () => {
14
+ // https://on.cypress.io/document
15
+ cy.document().should('have.property', 'charset').and('eq', 'UTF-8')
16
+ })
17
+
18
+ it('cy.title() - get the title', () => {
19
+ // https://on.cypress.io/title
20
+ cy.title().should('include', 'Kitchen Sink')
21
+ })
22
+ })
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Using fixtures to represent data",
3
+ "email": "hello@cypress.io",
4
+ "body": "Fixtures are a great way to mock data for responses to routes"
5
+ }