Skip to content

Commit

Permalink
Add animation name test case
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhsianw committed Oct 30, 2023
1 parent e8ad744 commit 7e6b76a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/files/animationName.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Used in `className`
@keyframes animationName1 {}

// Used in other classes
@keyframes animationName2 {}

.classUsingAnimation1 {
animation-name: animationName2;
}

// Using undefined animation name in another class
.classUsingAnimation2 {
animation-name: undefinedAnimationName;
}
Empty file.
39 changes: 39 additions & 0 deletions test/lib/rules/no-undef-class.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,43 @@ describe('no-undef-class', function () {
},
].map((testCase) => addFilenameOption(testCase)),
});

ruleTester.run('no-undef-class', rule, {
valid: [],
invalid: [
{
name: 'should support animation identifiers - using undefinedAnimationName in className',
code: `
import s from 'test/files/animationName.scss';
export default Foo = () => (
<div>
<div className={s.classUsingAnimation1}></div>
<div className={s.classUsingAnimation2}></div>
<div className={s.undefinedAnimationName}></div>
</div>
);
`,
errors: [
"Class or exported property 'undefinedAnimationName' not found",
],
},
{
name: 'should support animation identifiers - using undefinedAnimationName in another class',
code: `
import s from 'test/files/animationName.scss';
export default Foo = () => (
<div>
<div className={s.classUsingAnimation1}></div>
<div className={s.classUsingAnimation2}></div>
</div>
);
`,
errors: [
"Class or exported property 'undefinedAnimationName' not found",
],
},
].map((testCase) => addFilenameOption(testCase)),
});
});
35 changes: 35 additions & 0 deletions test/lib/rules/no-unused-class.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,39 @@ describe('no-unused-class', function () {
},
].map((testCase) => addFilenameOption(testCase)),
});

ruleTester.run('no-unused-class', rule, {
valid: [
{
name: 'should support animation identifiers - animationName1 used in className, animationName2 used in other classes',
code: `
import s from 'test/files/animationName.scss';
export default Foo = () => (
<div>
<div className={s.classUsingAnimation1}></div>
<div className={s.classUsingAnimation2}></div>
<div className={s.animationName1}></div>
</div>
);
`,
},
],
invalid: [
{
name: 'should support animation identifiers - animationName1 not used, animationName2 used in other classes',
code: `
import s from 'test/files/animationName.scss';
export default Foo = () => (
<div>
<div className={s.classUsingAnimation1}></div>
<div className={s.classUsingAnimation2}></div>
</div>
);
`,
errors: ['Unused classes found in animationName.scss: animationName1'],
},
].map((testCase) => addFilenameOption(testCase)),
});
});

0 comments on commit 7e6b76a

Please sign in to comment.