From 167137a6580fa94855f173600c8da1303a3dd989 Mon Sep 17 00:00:00 2001 From: Ben Monro Date: Thu, 10 Sep 2020 08:10:50 -0700 Subject: [PATCH] fix: fixed bug in toHaveAttribute check on style (#81) --- src/__tests__/lib/rules/prefer-to-have-style.js | 5 +++++ src/rules/prefer-to-have-style.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/__tests__/lib/rules/prefer-to-have-style.js b/src/__tests__/lib/rules/prefer-to-have-style.js index 75e447c..4816a00 100644 --- a/src/__tests__/lib/rules/prefer-to-have-style.js +++ b/src/__tests__/lib/rules/prefer-to-have-style.js @@ -11,6 +11,11 @@ ruleTester.run("prefer-to-have-style", rule, { `expect(el.style).toMatchSnapshot()`, `expect(el.style).toEqual(foo)`, `expect(el).toHaveAttribute("style")`, + `React.useLayoutEffect(() => { + if (foo) { + document.body.setAttribute("style", "foo"); + } + }, [foo]);`, ], invalid: [ { diff --git a/src/rules/prefer-to-have-style.js b/src/rules/prefer-to-have-style.js index ef20a7e..96b6955 100644 --- a/src/rules/prefer-to-have-style.js +++ b/src/rules/prefer-to-have-style.js @@ -109,7 +109,7 @@ export const create = (context) => ({ }, //expect(el).toHaveAttribute("style", "foo: bar"); - [`CallExpression[callee.property.name][arguments.0.value=style][arguments.1]`]( + [`CallExpression[callee.property.name=toHaveAttribute][arguments.0.value=style][arguments.1][callee.object.callee.name=expect]`]( node ) { context.report({