From 0c5f68bae3ffa5911bebb559e7d4200de5c3f694 Mon Sep 17 00:00:00 2001 From: Bill Glesias Date: Mon, 18 Sep 2023 15:01:15 -0400 Subject: [PATCH] fix: unsafe-to-chain-command: Fix the false positive of 'focus' regex matching 'focused' (#144) * fix(pencil): illustrate the false positive of 'focus' regex matching 'focused' * add test to ensure 'focus' does fail, in addition to 'focused' passing --------- Co-authored-by: Dominic Fraser --- lib/rules/unsafe-to-chain-command.js | 2 +- tests/lib/rules/unsafe-to-chain-command.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rules/unsafe-to-chain-command.js b/lib/rules/unsafe-to-chain-command.js index ac2e13d3..2ea527df 100644 --- a/lib/rules/unsafe-to-chain-command.js +++ b/lib/rules/unsafe-to-chain-command.js @@ -19,7 +19,7 @@ const unsafeToChainActions = [ 'check', 'dblclick', 'each', - 'focus', + 'focus$', 'rightclick', 'screenshot', 'scrollIntoView', diff --git a/tests/lib/rules/unsafe-to-chain-command.js b/tests/lib/rules/unsafe-to-chain-command.js index 2855b59a..c79b8e6e 100644 --- a/tests/lib/rules/unsafe-to-chain-command.js +++ b/tests/lib/rules/unsafe-to-chain-command.js @@ -14,6 +14,10 @@ ruleTester.run('action-ends-chain', rule, { code: 'cy.get("new-todo").type("todo A{enter}"); cy.get("new-todo").type("todo B{enter}"); cy.get("new-todo").should("have.class", "active");', parserOptions, }, + { + code: 'cy.focused().should("be.visible");', + parserOptions, + }, ], invalid: [ @@ -27,6 +31,11 @@ ruleTester.run('action-ends-chain', rule, { parserOptions, errors, }, + { + code: 'cy.get("new-todo").focus().should("have.class", "active");', + parserOptions, + errors, + }, { code: 'cy.get("new-todo").customType("todo A{enter}").customClick();', parserOptions,