Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support Cypress v9 #22

Merged
merged 2 commits into from Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 36 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -7,10 +7,45 @@ jobs:
- name: Checkout 🛎
uses: actions/checkout@v3

- name: Run tests 🧪
- name: Run Cypress tests 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v4

test-cypress-v9:
runs-on: ubuntu-20.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v3

- name: Install top dependencies 📦
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v4
with:
runTests: false

- name: Run Cypress v9 tests 🧪
uses: cypress-io/github-action@v4
with:
working-directory: cypress-v9

- uses: actions/upload-artifact@v2
name: Store any v9 screenshots 🖼
if: failure()
with:
name: cypress-screenshots-v9
path: cypress-v9/cypress/screenshots

release:
needs: [test, test-cypress-v9]
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout 🛎
uses: actions/checkout@v3

- name: Install only the semantic release 📦
run: npm install semantic-release

- name: Semantic Release 🚀
uses: cycjimmy/semantic-release-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@

> Easy conditional if-else logic for your Cypress tests

Tested with `cy.get`, `cy.contains`, `cy.find`, `.then`, `.within` commands in Cypress v10+ only.
Tested with `cy.get`, `cy.contains`, `cy.find`, `.then`, `.within` commands in Cypress v9 and v10+.

- 📺 [Introduction To Using cypress-if Plugin to Write Conditional Cypress Commands](https://youtu.be/TVwU0OvrVUA)
- 🎓 Covered in my [Cypress Plugins course](https://cypress.tips/courses/cypress-plugins)
Expand Down
5 changes: 5 additions & 0 deletions cypress-v9/cypress.json
@@ -0,0 +1,5 @@
{
"pluginsFile": false,
"supportFile": false,
"fixturesFolder": false
}
36 changes: 36 additions & 0 deletions cypress-v9/cypress/integration/spec.cy.js
@@ -0,0 +1,36 @@
/// <reference path="../../../src/index.d.ts" />
import '../../../src'

it('executes the IF branch', () => {
cy.wrap(1)
.if('equal', 1)
.then(cy.spy().as('if'))
.else()
.then(cy.spy().as('else'))
.finally()
.should('equal', 1)
cy.get('@if').should('have.been.calledOnce')
cy.get('@else').should('not.be.called')
})

describe('wrapped value', () => {
it('performs an action if the wrapped value is equal to 42', () => {
cy.wrap(42).if('equal', 42).then(cy.spy().as('action')).then(cy.log)
cy.get('@action').should('have.been.calledOnce')
})

it('does nothing if it is not 42', () => {
cy.wrap(1).if('equal', 42).then(cy.spy().as('action')).then(cy.log)
cy.get('@action').should('not.have.been.called')
})

context('.else', () => {
it('passes the subject to the else branch', () => {
cy.wrap(1).if('equal', 42).log('if branch').else().should('equal', 1)
})

it('passes the subject if().else()', () => {
cy.wrap(1).if('equal', 42).else().should('equal', 1)
})
})
})