Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions cypress/e2e/cyESLintPluginSample.cy.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
describe('eslint-plugin-cypress ruless', () => {
describe('eslint-plugin-cypress rules', () => {
beforeEach(() => {
cy.visit('./src/index.html')
})

it('lint error when assigning a cy command to a variable', () => {
const heading = cy.get('h1')
cy.get('h1')
})

it('lint error when waiting for an arbitrary number in ms', () => {
cy.wait(1000)
/**
* Instead, use a combination of `cy.intercetp()` with an alias (e.g., `.as`)
* Then, use `cy.wait('@alias')`
* For an example, visit the following URL shorturl.at/cgkoO
*/
})

it('fails when using `async` and `await`', async function() {
const heading = await cy.get('h1')
it('fails when using `async` and `await`', function() {
cy.get('h1')
})

it('lint error when chaining unsafe to chain commands', () => {
cy.get('input[type="text"]')
.as('textField')
.clear()
cy.get('@textField')
.type('Walmyr')
})

it('lint error when using { force: true }', () => {
cy.get('input[type="text"]').focus()
cy.get('button').click({ force: true })
cy.get('button').click()
})

it('lint error when taking a screenshot before an assertion', () => {
cy.get('h1').should('be.visible')
cy.contains('label', 'Nome:').should('be.visible')
cy.get('input[type="text"]').should('be.visible')
cy.contains('button', 'Enviar').should('be.visible')
cy.screenshot('test')
})

it('lint warning when not using a data-* attribute for selecting elements', () => {
cy.get('input[aria-label="name"]').should('be.visible')
cy.get('[data-test="name-text-field"]').should('be.visible')
})

it('lint error when leaving a cy.pause() command', () => {
cy.pause()
// Does something that does not pause the test.
})
})
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<body>
<h1>Saudações</h1>
<label for="name">Nome:</label>
<input type="text" aria-label="name" value="João" autofocus>
<input data-test="name-text-field" type="text" aria-label="name" value="João" autofocus>
<button id="ok-btn">Enviar</button>
<script>
const body = document.querySelector('body')
Expand Down