Skip to content

Commit

Permalink
finish the recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Mar 16, 2020
1 parent c4eadcd commit 36e6aa1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
14 changes: 12 additions & 2 deletions examples/testing-dom__select2/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# testing-dom__select2
> Testing Select2 widget
> Testing select elements and Select2 widgets
[Select2 site](https://select2.org/)
This example shows how end-to-end tests work with plain `<select>` HTML elements and with [Select2](https://select2.org/) widgets.

Find all tests in the [cypress/integration/spec.js](cypress/integration/spec.js) file

- selecting a single value using `<select>`
- selecting multiple values using `<select>`
- selecting a single value using `Select2`
- selecting multiple values using `Select2`
- removing one of the selected values using `Select2`

![demo](images/demo.gif)
14 changes: 10 additions & 4 deletions examples/testing-dom__select2/cypress/integration/spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// <reference types="cypress" />
import 'cypress-pipe'

beforeEach(() => {
cy.visit('index.html')
})
Expand Down Expand Up @@ -95,10 +97,14 @@ describe('select2', () => {
expect(list[2].title).to.equal('Vermont')
})

// TODO find a shorter way to express the assertion?
// .should('have.length', 3)
// .then((list) => list.map((k, el) => el.title))
// .should('deep.equal', ['Connecticut', 'Massachusetts', 'Vermont'])
// alternative: extract titles and then make an assertion
// and use https://github.com/NicholasBoll/cypress-pipe
// to preserve http://on.cypress.io/retry-ability
const getTitles = (list) => Cypress._.map(list, (li) => li.title)

cy.get('#states + .select2 .select2-selection__choice')
.pipe(getTitles)
.should('deep.equal', ['Connecticut', 'Massachusetts', 'Vermont'])
})

it('adds several states by typing', () => {
Expand Down
Binary file added examples/testing-dom__select2/images/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 15 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 36e6aa1

Please sign in to comment.