Skip to content

Commit

Permalink
fix: cypress test issues with trimmed strings
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Apr 2, 2024
1 parent fe6ecb0 commit 0590ae5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cypress/components/UploadPicker.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('UploadPicker rendering', () => {
}
cy.mount(UploadPicker, { propsData })
cy.get('[data-cy-upload-picker]').should('be.visible')
cy.get('[data-cy-upload-picker]').should('have.text', ' New ')
cy.get('[data-cy-upload-picker]').shouldHaveTrimmedText('New')
cy.get('[data-cy-upload-picker] [data-cy-upload-picker-input]').should('exist')
})

Expand Down Expand Up @@ -54,7 +54,7 @@ describe('UploadPicker valid uploads', () => {
cy.mount(UploadPicker, { propsData }).as('uploadPicker')

// Label is displayed before upload
cy.get('[data-cy-upload-picker]').should('have.text', ' New ')
cy.get('[data-cy-upload-picker]').shouldHaveTrimmedText('New')

// Check and init aliases
cy.get('[data-cy-upload-picker] [data-cy-upload-picker-input]').as('input').should('exist')
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('UploadPicker valid uploads', () => {
.should('not.be.visible')

// Label is displayed again after upload
cy.get('[data-cy-upload-picker] button').should('have.text', ' New ')
cy.get('[data-cy-upload-picker] button').shouldHaveTrimmedText('New')
})
})
})
Expand Down
14 changes: 14 additions & 0 deletions cypress/cypress.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { mount } from 'cypress/vue'

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount
shouldHaveTrimmedText: (text: string) => Chainable<JQuery<HTMLElement>>
}
}
}
9 changes: 9 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@
// https://on.cypress.io/custom-commands
// ***********************************************
import 'cypress-file-upload'

Cypress.Commands.add(
'shouldHaveTrimmedText',
{ prevSubject: true },
(subject: JQuery<HTMLElement>, text: string) => {
cy.wrap(subject)
.should(element => expect(element.text().trim()).to.equal(text))
},
)
5 changes: 4 additions & 1 deletion cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"@tsconfig/cypress/tsconfig.json",
"../tsconfig.json"
],
"include": ["./**/*.ts"],
"include": [
"./**/*.ts",
"./cypress.d.ts"
],
"compilerOptions": {
"types": ["cypress"],
"rootDir": "..",
Expand Down

0 comments on commit 0590ae5

Please sign in to comment.