no-force.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict'
  2. //------------------------------------------------------------------------------
  3. // Requirements
  4. //------------------------------------------------------------------------------
  5. const rule = require('../../../lib/rules/no-force')
  6. const RuleTester = require('eslint').RuleTester
  7. const errors = [{ messageId: 'unexpected' }]
  8. const parserOptions = { ecmaVersion: 6 }
  9. //------------------------------------------------------------------------------
  10. // Tests
  11. //------------------------------------------------------------------------------
  12. let ruleTester = new RuleTester()
  13. ruleTester.run('no-force', rule, {
  14. valid: [
  15. { code: `cy.get('button').click()`, parserOptions },
  16. { code: `cy.get('button').click({multiple: true})`, parserOptions },
  17. { code: `cy.get('button').dblclick()`, parserOptions },
  18. { code: `cy.get('input').type('somth')`, parserOptions },
  19. { code: `cy.get('input').type('somth', {anyoption: true})`, parserOptions, errors },
  20. { code: `cy.get('input').trigger('click', {anyoption: true})`, parserOptions, errors },
  21. { code: `cy.get('input').rightclick({anyoption: true})`, parserOptions, errors },
  22. { code: `cy.get('input').check()`, parserOptions, errors },
  23. { code: `cy.get('input').select()`, parserOptions, errors },
  24. { code: `cy.get('input').focus()`, parserOptions, errors },
  25. ],
  26. invalid: [
  27. { code: `cy.get('button').click({force: true})`, parserOptions, errors },
  28. { code: `cy.get('button').dblclick({force: true})`, parserOptions, errors },
  29. { code: `cy.get('input').type('somth', {force: true})`, parserOptions, errors },
  30. { code: `cy.get('div').find('.foo').type('somth', {force: true})`, parserOptions, errors },
  31. { code: `cy.get('div').find('.foo').find('.bar').click({force: true})`, parserOptions, errors },
  32. { code: `cy.get('div').find('.foo').find('.bar').trigger('change', {force: true})`, parserOptions, errors },
  33. { code: `cy.get('input').trigger('click', {force: true})`, parserOptions, errors },
  34. { code: `cy.get('input').rightclick({force: true})`, parserOptions, errors },
  35. { code: `cy.get('input').check({force: true})`, parserOptions, errors },
  36. { code: `cy.get('input').select({force: true})`, parserOptions, errors },
  37. { code: `cy.get('input').focus({force: true})`, parserOptions, errors },
  38. ],
  39. })