index.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'
  2. Given('I open the home page', () => {
  3. cy.visit(Cypress.env('BASE_URL'), {
  4. onBeforeLoad(win) {
  5. cy.stub(win, 'matchMedia')
  6. .callThrough()
  7. .withArgs('(prefers-color-scheme: dark)')
  8. .returns({
  9. matches: false,
  10. addListener() {}
  11. })
  12. }
  13. })
  14. })
  15. Given('I refresh the page', () => {
  16. cy.reload()
  17. })
  18. Given('I can see the {string} element', (attr: string) => {
  19. cy.dataCy(attr)
  20. })
  21. When('I click on the {string} element', (attr: string) => {
  22. const el = cy.dataCy(attr)
  23. el.click()
  24. })
  25. When(
  26. 'I trigger the {string} event on the {string} element',
  27. (event: string, attr: string) => {
  28. const el = cy.dataCy(attr)
  29. el.trigger(event)
  30. }
  31. )
  32. Then('I see {string} in the title', (val: string) => {
  33. cy.title().should('include', val)
  34. })
  35. Then(
  36. 'The {string} style on the {string} element should be {string}',
  37. (style: string, attr: string, val: string) => {
  38. const el = cy.dataCy(attr)
  39. el.should('have.css', style, val)
  40. }
  41. )
  42. Then(
  43. 'The {string} element should have class {string}',
  44. (attr: string, val: string) => {
  45. const el = cy.dataCy(attr)
  46. el.should('have.class', val)
  47. }
  48. )
  49. Then(
  50. 'The {string} element should not have class {string}',
  51. (attr: string, val: string) => {
  52. const el = cy.dataCy(attr)
  53. el.should('not.have.class', val)
  54. }
  55. )
  56. Then('I should see the {string} element', (attr: string) => {
  57. const el = cy.dataCy(attr)
  58. el.should('be.visible')
  59. })
  60. Cypress.on('uncaught:exception', (err, _runnable) => {
  61. console.error(err)
  62. })