@cypress/skip-test
Simple commands to skip a test based on platform, browser or an url
it('skips this test when running on Mac', () => {
cy.log('about to run custom command to skip this test')
.wait(1000)
.skipOn('mac')
})
Install
npm install -D @cypress/skip-test
Example
You can use this module as custom Cypress commands cy.skipOn
and cy.onlyOn
or by importing its functions. To use custom commands like cy.skipOn
, add this module to your support file cypress/support/index.js
require('@cypress/skip-test/support')
cy.skipOn
Skip this test if running in Electron browser
it('only runs on Electron', () => {
cy.skipOn('electron')
})
Skip this test if running on Windows platform
it('runs on Linux and Mac', () => {
cy.skipOn('windows')
})
cy.onlyOn
Continues the test only when running on Mac, skips when running on any other platform
it('runs on Mac only', () => {
cy.onlyOn('mac')
})
Continues this test only when running against localhost
. Use baseUrl
to set the url to compare.
it('only tests localhost', () => {
cy.onlyOn('localhost')
})
imports
import { onlyOn, skipOn } from '@cypress/skip-test'
it('runs only on Mac', () => {
onlyOn('mac')
})
it('skips on Mac', () => {
skipOn('darwin')
})
imports with callback
Instead of dynamically skipping a test at run-time, you can hide entire blocks of tests using the callback format.
import { onlyOn, skipOn } from '@cypress/skip-test'
onlyOn('mac', () => {
describe('Mac tests', () => {
it('works', () => {})
})
})
skipOn('mac', () => {
it('hides this test on Mac', () => {})
})
Tip: you can nest the callbacks to combine the conditions
onlyOn('mac', () => {
onlyOn('chrome', () => {
it('works', () => {})
})
})
Notes
You can chain conditions together
it('combination of skip and only', () => {
cy.skipOn('firefox')
cy.onlyOn('electron').onlyOn('mac')
cy.log('running test')
})
If the test runs, it will print the conditions in the command log
Intellisense
To get typings, reference this module, for example by using reference
comment
For more details read Cypress Intelligent Completion Guide
Warning
Skipping tests in Mocha at run-time skips the afterEach
hooks. In this example, afterEach
will be skipped, and after
hook will run.
it('example', () => {
cy.skipOn('mac')
})
afterEach(() => {
})
after(() => {
})
Authors
MIT License