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
package/circle.yml CHANGED
@@ -1,17 +1,37 @@
1
1
  version: 2.1
2
2
 
3
+ executors:
4
+ docker-executor:
5
+ docker:
6
+ - image: cimg/node:22.14.0
7
+ resource_class: medium
8
+
3
9
  workflows:
4
- version: 2.1
5
10
  main:
6
11
  jobs:
7
12
  - lint
8
13
  - test-v8
9
14
  - test-v9
15
+
16
+ - build-test-project
17
+ - test-test-project:
18
+ matrix:
19
+ parameters:
20
+ eslint-version: ['9']
21
+ config-file: [
22
+ # configurations correspond to examples in README
23
+ 'default',
24
+ 'recommended',
25
+ 'globals',
26
+ ]
27
+ requires:
28
+ - build-test-project
10
29
  - release:
11
30
  requires:
12
31
  - lint
13
32
  - test-v8
14
33
  - test-v9
34
+ - test-test-project
15
35
  filters:
16
36
  branches:
17
37
  only:
@@ -19,8 +39,7 @@ workflows:
19
39
 
20
40
  jobs:
21
41
  lint:
22
- docker:
23
- - image: cimg/node:22.11.0
42
+ executor: docker-executor
24
43
  steps:
25
44
  - checkout
26
45
  - run:
@@ -34,8 +53,7 @@ jobs:
34
53
  command: npm run lint
35
54
 
36
55
  test-v8:
37
- docker:
38
- - image: cimg/node:22.11.0
56
+ executor: docker-executor
39
57
  steps:
40
58
  - checkout
41
59
  - run:
@@ -52,8 +70,7 @@ jobs:
52
70
  command: npm run test:legacy
53
71
 
54
72
  test-v9:
55
- docker:
56
- - image: cimg/node:22.11.0
73
+ executor: docker-executor
57
74
  steps:
58
75
  - checkout
59
76
  - run:
@@ -69,9 +86,65 @@ jobs:
69
86
  name: Test ESLint 9
70
87
  command: npm test
71
88
 
89
+ build-test-project:
90
+ executor: docker-executor
91
+ steps:
92
+ - checkout
93
+ - run:
94
+ name: Install dependencies
95
+ command: npm ci
96
+ - run:
97
+ name: Build tarball
98
+ command: npm pack
99
+ - run:
100
+ name: Get version
101
+ command: |
102
+ echo "PLUGIN_VERSION=$(jq -r '.version' package.json)" >> $BASH_ENV
103
+ cp $BASH_ENV bash.env
104
+ - persist_to_workspace:
105
+ root: .
106
+ paths:
107
+ - eslint-plugin-cypress-*.tgz
108
+ - bash.env
109
+
110
+ test-test-project:
111
+ description: Run ESLint with different configurations
112
+ parameters:
113
+ eslint-version:
114
+ description: Version of ESLint to use
115
+ default: 'latest'
116
+ type: string
117
+ config-file:
118
+ description: Configuration file
119
+ default: 'default'
120
+ type: string
121
+ executor: docker-executor
122
+ working_directory: ./test-project
123
+ steps:
124
+ - checkout:
125
+ path: ../
126
+ - attach_workspace:
127
+ at: .
128
+ - run:
129
+ name: Get plugin version
130
+ command: |
131
+ cat bash.env >> $BASH_ENV
132
+ - run:
133
+ name: Install dependencies
134
+ command: |
135
+ npm install eslint@<< parameters.eslint-version>> ./eslint-plugin-cypress-$PLUGIN_VERSION.tgz -D
136
+ - run:
137
+ name: Display ESLint version
138
+ command: |
139
+ npx eslint --version
140
+ - run: echo Testing a << parameters.config-file >> configuration
141
+ - run:
142
+ name: Lint with example configuration
143
+ command: |
144
+ npx eslint --config ./eslint-configs/eslint.<< parameters.config-file >>.mjs .
145
+
72
146
  release:
73
- docker:
74
- - image: cimg/node:22.11.0
147
+ executor: docker-executor
75
148
  steps:
76
149
  - checkout
77
150
  - run:
package/eslint.config.mjs CHANGED
@@ -7,6 +7,7 @@ export default [
7
7
  pluginJs.configs.recommended,
8
8
  eslintPlugin.configs['flat/recommended'],
9
9
  mochaPlugin.configs.flat.recommended,
10
+ {ignores: ['test-project/']},
10
11
  {
11
12
  languageOptions: {
12
13
  globals: globals.node
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-cypress",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "An ESLint plugin for projects using Cypress",
5
5
  "main": "legacy.js",
6
6
  "exports": {
@@ -26,15 +26,15 @@
26
26
  "eslint": ">=9"
27
27
  },
28
28
  "dependencies": {
29
- "globals": "^15.11.0"
29
+ "globals": "^15.15.0"
30
30
  },
31
31
  "devDependencies": {
32
- "eslint": "^9.13.0",
33
- "eslint-plugin-eslint-plugin": "^6.3.1",
32
+ "eslint": "^9.24.0",
33
+ "eslint-plugin-eslint-plugin": "^6.4.0",
34
34
  "eslint-plugin-mocha": "^10.5.0",
35
- "husky": "^9.1.6",
35
+ "husky": "^9.1.7",
36
36
  "jest": "^29.7.0",
37
- "semantic-release": "24.2.0"
37
+ "semantic-release": "24.2.3"
38
38
  },
39
39
  "scripts": {
40
40
  "lint": "eslint \"*.js\" \"**/**/*.js\"",
@@ -0,0 +1,48 @@
1
+ # Test-project
2
+
3
+ This test project was generated via the Cypress App.
4
+
5
+ This project can be updated to the latest Cypress default scaffolded E2E test specs by carrying out the following steps in the directory `/test-project`:
6
+
7
+ ```shell
8
+ rm -rf cypress cypress.config.js
9
+ npm install cypress@latest --no-package-lock
10
+ npx cypress open
11
+ ```
12
+
13
+ - Select "Continue" for "What's New in Cypress" if displayed
14
+ - Select "E2E Testing"
15
+ - Select "Continue" in "Configuration files"
16
+ - Select "Electron" browser
17
+ - Select "Start E2E Testing in Electron"
18
+ - Select "Scaffold example specs"
19
+ - Close all Cypress windows
20
+
21
+ Test that scaffolded specs run:
22
+
23
+ ```shell
24
+ npm test
25
+ ```
26
+
27
+ Remove Cypress from `package.json`:
28
+
29
+ ```shell
30
+ npm uninstall cypress --no-package-lock
31
+ ```
32
+
33
+ ## Tests
34
+
35
+ Tests are run via [circle.yml](../circle.yml).
36
+
37
+ To test the project locally:
38
+
39
+ ```shell
40
+ cd test-project
41
+ npm install eslint@latest eslint-plugin-cypress@latest cypress@latest -D
42
+ npx cypress run
43
+ npx eslint
44
+ ```
45
+
46
+ Do not commit the changes from installing the above dependencies.
47
+ The CircleCI pipeline dynamically installs the latest `eslint*` dependencies.
48
+ Cypress is not needed for the CircleCI tests.
@@ -0,0 +1,143 @@
1
+ /// <reference types="cypress" />
2
+
3
+ // Welcome to Cypress!
4
+ //
5
+ // This spec file contains a variety of sample tests
6
+ // for a todo list app that are designed to demonstrate
7
+ // the power of writing tests in Cypress.
8
+ //
9
+ // To learn more about how Cypress works and
10
+ // what makes it such an awesome testing tool,
11
+ // please read our getting started guide:
12
+ // https://on.cypress.io/introduction-to-cypress
13
+
14
+ describe('example to-do app', () => {
15
+ beforeEach(() => {
16
+ // Cypress starts out with a blank slate for each test
17
+ // so we must tell it to visit our website with the `cy.visit()` command.
18
+ // Since we want to visit the same URL at the start of all our tests,
19
+ // we include it in our beforeEach function so that it runs before each test
20
+ cy.visit('https://example.cypress.io/todo')
21
+ })
22
+
23
+ it('displays two todo items by default', () => {
24
+ // We use the `cy.get()` command to get all elements that match the selector.
25
+ // Then, we use `should` to assert that there are two matched items,
26
+ // which are the two default items.
27
+ cy.get('.todo-list li').should('have.length', 2)
28
+
29
+ // We can go even further and check that the default todos each contain
30
+ // the correct text. We use the `first` and `last` functions
31
+ // to get just the first and last matched elements individually,
32
+ // and then perform an assertion with `should`.
33
+ cy.get('.todo-list li').first().should('have.text', 'Pay electric bill')
34
+ cy.get('.todo-list li').last().should('have.text', 'Walk the dog')
35
+ })
36
+
37
+ it('can add new todo items', () => {
38
+ // We'll store our item text in a variable so we can reuse it
39
+ const newItem = 'Feed the cat'
40
+
41
+ // Let's get the input element and use the `type` command to
42
+ // input our new list item. After typing the content of our item,
43
+ // we need to type the enter key as well in order to submit the input.
44
+ // This input has a data-test attribute so we'll use that to select the
45
+ // element in accordance with best practices:
46
+ // https://on.cypress.io/selecting-elements
47
+ cy.get('[data-test=new-todo]').type(`${newItem}{enter}`)
48
+
49
+ // Now that we've typed our new item, let's check that it actually was added to the list.
50
+ // Since it's the newest item, it should exist as the last element in the list.
51
+ // In addition, with the two default items, we should have a total of 3 elements in the list.
52
+ // Since assertions yield the element that was asserted on,
53
+ // we can chain both of these assertions together into a single statement.
54
+ cy.get('.todo-list li')
55
+ .should('have.length', 3)
56
+ .last()
57
+ .should('have.text', newItem)
58
+ })
59
+
60
+ it('can check off an item as completed', () => {
61
+ // In addition to using the `get` command to get an element by selector,
62
+ // we can also use the `contains` command to get an element by its contents.
63
+ // However, this will yield the <label>, which is lowest-level element that contains the text.
64
+ // In order to check the item, we'll find the <input> element for this <label>
65
+ // by traversing up the dom to the parent element. From there, we can `find`
66
+ // the child checkbox <input> element and use the `check` command to check it.
67
+ cy.contains('Pay electric bill')
68
+ .parent()
69
+ .find('input[type=checkbox]')
70
+ .check()
71
+
72
+ // Now that we've checked the button, we can go ahead and make sure
73
+ // that the list element is now marked as completed.
74
+ // Again we'll use `contains` to find the <label> element and then use the `parents` command
75
+ // to traverse multiple levels up the dom until we find the corresponding <li> element.
76
+ // Once we get that element, we can assert that it has the completed class.
77
+ cy.contains('Pay electric bill')
78
+ .parents('li')
79
+ .should('have.class', 'completed')
80
+ })
81
+
82
+ context('with a checked task', () => {
83
+ beforeEach(() => {
84
+ // We'll take the command we used above to check off an element
85
+ // Since we want to perform multiple tests that start with checking
86
+ // one element, we put it in the beforeEach hook
87
+ // so that it runs at the start of every test.
88
+ cy.contains('Pay electric bill')
89
+ .parent()
90
+ .find('input[type=checkbox]')
91
+ .check()
92
+ })
93
+
94
+ it('can filter for uncompleted tasks', () => {
95
+ // We'll click on the "active" button in order to
96
+ // display only incomplete items
97
+ cy.contains('Active').click()
98
+
99
+ // After filtering, we can assert that there is only the one
100
+ // incomplete item in the list.
101
+ cy.get('.todo-list li')
102
+ .should('have.length', 1)
103
+ .first()
104
+ .should('have.text', 'Walk the dog')
105
+
106
+ // For good measure, let's also assert that the task we checked off
107
+ // does not exist on the page.
108
+ cy.contains('Pay electric bill').should('not.exist')
109
+ })
110
+
111
+ it('can filter for completed tasks', () => {
112
+ // We can perform similar steps as the test above to ensure
113
+ // that only completed tasks are shown
114
+ cy.contains('Completed').click()
115
+
116
+ cy.get('.todo-list li')
117
+ .should('have.length', 1)
118
+ .first()
119
+ .should('have.text', 'Pay electric bill')
120
+
121
+ cy.contains('Walk the dog').should('not.exist')
122
+ })
123
+
124
+ it('can delete all completed tasks', () => {
125
+ // First, let's click the "Clear completed" button
126
+ // `contains` is actually serving two purposes here.
127
+ // First, it's ensuring that the button exists within the dom.
128
+ // This button only appears when at least one task is checked
129
+ // so this command is implicitly verifying that it does exist.
130
+ // Second, it selects the button so we can click it.
131
+ cy.contains('Clear completed').click()
132
+
133
+ // Then we can make sure that there is only one element
134
+ // in the list and our element does not exist
135
+ cy.get('.todo-list li')
136
+ .should('have.length', 1)
137
+ .should('not.have.text', 'Pay electric bill')
138
+
139
+ // Finally, make sure that the clear button no longer exists.
140
+ cy.contains('Clear completed').should('not.exist')
141
+ })
142
+ })
143
+ })
@@ -0,0 +1,321 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Actions', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/actions')
6
+ })
7
+
8
+ // https://on.cypress.io/interacting-with-elements
9
+
10
+ it('.type() - type into a DOM element', () => {
11
+ // https://on.cypress.io/type
12
+ cy.get('.action-email').type('fake@email.com')
13
+ cy.get('.action-email').should('have.value', 'fake@email.com')
14
+
15
+ // .type() with special character sequences
16
+ cy.get('.action-email').type('{leftarrow}{rightarrow}{uparrow}{downarrow}')
17
+ cy.get('.action-email').type('{del}{selectall}{backspace}')
18
+
19
+ // .type() with key modifiers
20
+ cy.get('.action-email').type('{alt}{option}') //these are equivalent
21
+ cy.get('.action-email').type('{ctrl}{control}') //these are equivalent
22
+ cy.get('.action-email').type('{meta}{command}{cmd}') //these are equivalent
23
+ cy.get('.action-email').type('{shift}')
24
+
25
+ // Delay each keypress by 0.1 sec
26
+ cy.get('.action-email').type('slow.typing@email.com', { delay: 100 })
27
+ cy.get('.action-email').should('have.value', 'slow.typing@email.com')
28
+
29
+ cy.get('.action-disabled')
30
+ // Ignore error checking prior to type
31
+ // like whether the input is visible or disabled
32
+ .type('disabled error checking', { force: true })
33
+ cy.get('.action-disabled').should('have.value', 'disabled error checking')
34
+ })
35
+
36
+ it('.focus() - focus on a DOM element', () => {
37
+ // https://on.cypress.io/focus
38
+ cy.get('.action-focus').focus()
39
+ cy.get('.action-focus').should('have.class', 'focus')
40
+ .prev().should('have.attr', 'style', 'color: orange;')
41
+ })
42
+
43
+ it('.blur() - blur off a DOM element', () => {
44
+ // https://on.cypress.io/blur
45
+ cy.get('.action-blur').type('About to blur')
46
+ cy.get('.action-blur').blur()
47
+ cy.get('.action-blur').should('have.class', 'error')
48
+ .prev().should('have.attr', 'style', 'color: red;')
49
+ })
50
+
51
+ it('.clear() - clears an input or textarea element', () => {
52
+ // https://on.cypress.io/clear
53
+ cy.get('.action-clear').type('Clear this text')
54
+ cy.get('.action-clear').should('have.value', 'Clear this text')
55
+ cy.get('.action-clear').clear()
56
+ cy.get('.action-clear').should('have.value', '')
57
+ })
58
+
59
+ it('.submit() - submit a form', () => {
60
+ // https://on.cypress.io/submit
61
+ cy.get('.action-form')
62
+ .find('[type="text"]').type('HALFOFF')
63
+
64
+ cy.get('.action-form').submit()
65
+ cy.get('.action-form').next().should('contain', 'Your form has been submitted!')
66
+ })
67
+
68
+ it('.click() - click on a DOM element', () => {
69
+ // https://on.cypress.io/click
70
+ cy.get('.action-btn').click()
71
+
72
+ // You can click on 9 specific positions of an element:
73
+ // -----------------------------------
74
+ // | topLeft top topRight |
75
+ // | |
76
+ // | |
77
+ // | |
78
+ // | left center right |
79
+ // | |
80
+ // | |
81
+ // | |
82
+ // | bottomLeft bottom bottomRight |
83
+ // -----------------------------------
84
+
85
+ // clicking in the center of the element is the default
86
+ cy.get('#action-canvas').click()
87
+
88
+ cy.get('#action-canvas').click('topLeft')
89
+ cy.get('#action-canvas').click('top')
90
+ cy.get('#action-canvas').click('topRight')
91
+ cy.get('#action-canvas').click('left')
92
+ cy.get('#action-canvas').click('right')
93
+ cy.get('#action-canvas').click('bottomLeft')
94
+ cy.get('#action-canvas').click('bottom')
95
+ cy.get('#action-canvas').click('bottomRight')
96
+
97
+ // .click() accepts an x and y coordinate
98
+ // that controls where the click occurs :)
99
+
100
+ cy.get('#action-canvas')
101
+ cy.get('#action-canvas').click(80, 75) // click 80px on x coord and 75px on y coord
102
+ cy.get('#action-canvas').click(170, 75)
103
+ cy.get('#action-canvas').click(80, 165)
104
+ cy.get('#action-canvas').click(100, 185)
105
+ cy.get('#action-canvas').click(125, 190)
106
+ cy.get('#action-canvas').click(150, 185)
107
+ cy.get('#action-canvas').click(170, 165)
108
+
109
+ // click multiple elements by passing multiple: true
110
+ cy.get('.action-labels>.label').click({ multiple: true })
111
+
112
+ // Ignore error checking prior to clicking
113
+ cy.get('.action-opacity>.btn').click({ force: true })
114
+ })
115
+
116
+ it('.dblclick() - double click on a DOM element', () => {
117
+ // https://on.cypress.io/dblclick
118
+
119
+ // Our app has a listener on 'dblclick' event in our 'scripts.js'
120
+ // that hides the div and shows an input on double click
121
+ cy.get('.action-div').dblclick()
122
+ cy.get('.action-div').should('not.be.visible')
123
+ cy.get('.action-input-hidden').should('be.visible')
124
+ })
125
+
126
+ it('.rightclick() - right click on a DOM element', () => {
127
+ // https://on.cypress.io/rightclick
128
+
129
+ // Our app has a listener on 'contextmenu' event in our 'scripts.js'
130
+ // that hides the div and shows an input on right click
131
+ cy.get('.rightclick-action-div').rightclick()
132
+ cy.get('.rightclick-action-div').should('not.be.visible')
133
+ cy.get('.rightclick-action-input-hidden').should('be.visible')
134
+ })
135
+
136
+ it('.check() - check a checkbox or radio element', () => {
137
+ // https://on.cypress.io/check
138
+
139
+ // By default, .check() will check all
140
+ // matching checkbox or radio elements in succession, one after another
141
+ cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]').check()
142
+ cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]').should('be.checked')
143
+
144
+ cy.get('.action-radios [type="radio"]').not('[disabled]').check()
145
+ cy.get('.action-radios [type="radio"]').not('[disabled]').should('be.checked')
146
+
147
+ // .check() accepts a value argument
148
+ cy.get('.action-radios [type="radio"]').check('radio1')
149
+ cy.get('.action-radios [type="radio"]').should('be.checked')
150
+
151
+ // .check() accepts an array of values
152
+ cy.get('.action-multiple-checkboxes [type="checkbox"]').check(['checkbox1', 'checkbox2'])
153
+ cy.get('.action-multiple-checkboxes [type="checkbox"]').should('be.checked')
154
+
155
+ // Ignore error checking prior to checking
156
+ cy.get('.action-checkboxes [disabled]').check({ force: true })
157
+ cy.get('.action-checkboxes [disabled]').should('be.checked')
158
+
159
+ cy.get('.action-radios [type="radio"]').check('radio3', { force: true })
160
+ cy.get('.action-radios [type="radio"]').should('be.checked')
161
+ })
162
+
163
+ it('.uncheck() - uncheck a checkbox element', () => {
164
+ // https://on.cypress.io/uncheck
165
+
166
+ // By default, .uncheck() will uncheck all matching
167
+ // checkbox elements in succession, one after another
168
+ cy.get('.action-check [type="checkbox"]')
169
+ .not('[disabled]')
170
+ .uncheck()
171
+ cy.get('.action-check [type="checkbox"]')
172
+ .not('[disabled]')
173
+ .should('not.be.checked')
174
+
175
+ // .uncheck() accepts a value argument
176
+ cy.get('.action-check [type="checkbox"]')
177
+ .check('checkbox1')
178
+ cy.get('.action-check [type="checkbox"]')
179
+ .uncheck('checkbox1')
180
+ cy.get('.action-check [type="checkbox"][value="checkbox1"]')
181
+ .should('not.be.checked')
182
+
183
+ // .uncheck() accepts an array of values
184
+ cy.get('.action-check [type="checkbox"]')
185
+ .check(['checkbox1', 'checkbox3'])
186
+ cy.get('.action-check [type="checkbox"]')
187
+ .uncheck(['checkbox1', 'checkbox3'])
188
+ cy.get('.action-check [type="checkbox"][value="checkbox1"]')
189
+ .should('not.be.checked')
190
+ cy.get('.action-check [type="checkbox"][value="checkbox3"]')
191
+ .should('not.be.checked')
192
+
193
+ // Ignore error checking prior to unchecking
194
+ cy.get('.action-check [disabled]').uncheck({ force: true })
195
+ cy.get('.action-check [disabled]').should('not.be.checked')
196
+ })
197
+
198
+ it('.select() - select an option in a <select> element', () => {
199
+ // https://on.cypress.io/select
200
+
201
+ // at first, no option should be selected
202
+ cy.get('.action-select')
203
+ .should('have.value', '--Select a fruit--')
204
+
205
+ // Select option(s) with matching text content
206
+ cy.get('.action-select').select('apples')
207
+ // confirm the apples were selected
208
+ // note that each value starts with "fr-" in our HTML
209
+ cy.get('.action-select').should('have.value', 'fr-apples')
210
+
211
+ cy.get('.action-select-multiple')
212
+ .select(['apples', 'oranges', 'bananas'])
213
+ cy.get('.action-select-multiple')
214
+ // when getting multiple values, invoke "val" method first
215
+ .invoke('val')
216
+ .should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])
217
+
218
+ // Select option(s) with matching value
219
+ cy.get('.action-select').select('fr-bananas')
220
+ cy.get('.action-select')
221
+ // can attach an assertion right away to the element
222
+ .should('have.value', 'fr-bananas')
223
+
224
+ cy.get('.action-select-multiple')
225
+ .select(['fr-apples', 'fr-oranges', 'fr-bananas'])
226
+ cy.get('.action-select-multiple')
227
+ .invoke('val')
228
+ .should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])
229
+
230
+ // assert the selected values include oranges
231
+ cy.get('.action-select-multiple')
232
+ .invoke('val').should('include', 'fr-oranges')
233
+ })
234
+
235
+ it('.scrollIntoView() - scroll an element into view', () => {
236
+ // https://on.cypress.io/scrollintoview
237
+
238
+ // normally all of these buttons are hidden,
239
+ // because they're not within
240
+ // the viewable area of their parent
241
+ // (we need to scroll to see them)
242
+ cy.get('#scroll-horizontal button')
243
+ .should('not.be.visible')
244
+
245
+ // scroll the button into view, as if the user had scrolled
246
+ cy.get('#scroll-horizontal button').scrollIntoView()
247
+ cy.get('#scroll-horizontal button')
248
+ .should('be.visible')
249
+
250
+ cy.get('#scroll-vertical button')
251
+ .should('not.be.visible')
252
+
253
+ // Cypress handles the scroll direction needed
254
+ cy.get('#scroll-vertical button').scrollIntoView()
255
+ cy.get('#scroll-vertical button')
256
+ .should('be.visible')
257
+
258
+ cy.get('#scroll-both button')
259
+ .should('not.be.visible')
260
+
261
+ // Cypress knows to scroll to the right and down
262
+ cy.get('#scroll-both button').scrollIntoView()
263
+ cy.get('#scroll-both button')
264
+ .should('be.visible')
265
+ })
266
+
267
+ it('.trigger() - trigger an event on a DOM element', () => {
268
+ // https://on.cypress.io/trigger
269
+
270
+ // To interact with a range input (slider)
271
+ // we need to set its value & trigger the
272
+ // event to signal it changed
273
+
274
+ // Here, we invoke jQuery's val() method to set
275
+ // the value and trigger the 'change' event
276
+ cy.get('.trigger-input-range')
277
+ .invoke('val', 25)
278
+ cy.get('.trigger-input-range')
279
+ .trigger('change')
280
+ cy.get('.trigger-input-range')
281
+ .get('input[type=range]').siblings('p')
282
+ .should('have.text', '25')
283
+ })
284
+
285
+ it('cy.scrollTo() - scroll the window or element to a position', () => {
286
+ // https://on.cypress.io/scrollto
287
+
288
+ // You can scroll to 9 specific positions of an element:
289
+ // -----------------------------------
290
+ // | topLeft top topRight |
291
+ // | |
292
+ // | |
293
+ // | |
294
+ // | left center right |
295
+ // | |
296
+ // | |
297
+ // | |
298
+ // | bottomLeft bottom bottomRight |
299
+ // -----------------------------------
300
+
301
+ // if you chain .scrollTo() off of cy, we will
302
+ // scroll the entire window
303
+ cy.scrollTo('bottom')
304
+
305
+ cy.get('#scrollable-horizontal').scrollTo('right')
306
+
307
+ // or you can scroll to a specific coordinate:
308
+ // (x axis, y axis) in pixels
309
+ cy.get('#scrollable-vertical').scrollTo(250, 250)
310
+
311
+ // or you can scroll to a specific percentage
312
+ // of the (width, height) of the element
313
+ cy.get('#scrollable-both').scrollTo('75%', '25%')
314
+
315
+ // control the easing of the scroll (default is 'swing')
316
+ cy.get('#scrollable-vertical').scrollTo('center', { easing: 'linear' })
317
+
318
+ // control the duration of the scroll (in ms)
319
+ cy.get('#scrollable-both').scrollTo('center', { duration: 2000 })
320
+ })
321
+ })