From 61a9de1bbfc1da5a1858b3ee424c96927f166a5f Mon Sep 17 00:00:00 2001 From: Emil Goldsmith Olesen Date: Tue, 4 May 2021 15:51:16 +0200 Subject: [PATCH] fix: Fix crashing bug in no-force rule when using spread operator (#79) --- lib/rules/no-force.js | 2 +- tests/lib/rules/no-force.js | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/rules/no-force.js b/lib/rules/no-force.js index 123f6e23..ddf460e7 100644 --- a/lib/rules/no-force.js +++ b/lib/rules/no-force.js @@ -42,7 +42,7 @@ module.exports = { return node.arguments && node.arguments.length && node.arguments.some((arg) => { - return arg.type === 'ObjectExpression' && arg.properties.some((propNode) => propNode.key.name === 'force') + return arg.type === 'ObjectExpression' && arg.properties.some((propNode) => propNode.key && propNode.key.name === 'force') }) } diff --git a/tests/lib/rules/no-force.js b/tests/lib/rules/no-force.js index ad6aa0cd..86439258 100644 --- a/tests/lib/rules/no-force.js +++ b/tests/lib/rules/no-force.js @@ -9,7 +9,7 @@ const rule = require('../../../lib/rules/no-force') const RuleTester = require('eslint').RuleTester const errors = [{ messageId: 'unexpected' }] -const parserOptions = { ecmaVersion: 6 } +const parserOptions = { ecmaVersion: 2018 } //------------------------------------------------------------------------------ // Tests @@ -24,12 +24,13 @@ ruleTester.run('no-force', rule, { { code: `cy.get('button').click({multiple: true})`, parserOptions }, { code: `cy.get('button').dblclick()`, parserOptions }, { code: `cy.get('input').type('somth')`, parserOptions }, - { code: `cy.get('input').type('somth', {anyoption: true})`, parserOptions, errors }, - { code: `cy.get('input').trigger('click', {anyoption: true})`, parserOptions, errors }, - { code: `cy.get('input').rightclick({anyoption: true})`, parserOptions, errors }, - { code: `cy.get('input').check()`, parserOptions, errors }, - { code: `cy.get('input').select()`, parserOptions, errors }, - { code: `cy.get('input').focus()`, parserOptions, errors }, + { code: `cy.get('input').type('somth', {anyoption: true})`, parserOptions }, + { code: `cy.get('input').trigger('click', {anyoption: true})`, parserOptions }, + { code: `cy.get('input').rightclick({anyoption: true})`, parserOptions }, + { code: `cy.get('input').check()`, parserOptions }, + { code: `cy.get('input').select()`, parserOptions }, + { code: `cy.get('input').focus()`, parserOptions }, + { code: `cy.document().trigger("keydown", { ...event })`, parserOptions }, ], invalid: [