This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
"plugins": [ | ||
"react" | ||
], | ||
"env": { | ||
"jest": true | ||
}, | ||
"rules": { | ||
"consistent-return": 0, | ||
"func-names": 0, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { classNames } from './utils'; | ||
|
||
describe('utils', () => { | ||
describe('classNames', () => { | ||
it('should calculate string input class ', () => { | ||
const styles = { | ||
myClass: 'my class', | ||
}; | ||
expect(classNames(styles, 'myClass')) | ||
.toBe(styles.myClass); | ||
}); | ||
|
||
it('should calculate int arg classes', () => { | ||
const styles = { | ||
1: 'uno', | ||
}; | ||
expect(classNames(styles, 1)) | ||
.toBe(`${styles[1]}`); | ||
}); | ||
|
||
it('should calculate multiple arg classes', () => { | ||
const styles = { | ||
myClass: 'my class', | ||
myOtherClass: 'my other class', | ||
}; | ||
|
||
expect(classNames(styles, 'myClass', 'myOtherClass')) | ||
.toBe(`${styles.myClass} ${styles.myOtherClass}`); | ||
}); | ||
|
||
it('should calculate array of classes', () => { | ||
const styles = { | ||
myClass: 'my class', | ||
myOtherClass: 'my other class', | ||
}; | ||
expect(classNames(styles, ['myClass', 'myOtherClass'])) | ||
.toBe(`${styles.myClass} ${styles.myOtherClass}`); | ||
}); | ||
|
||
it('should not duplicate classes', () => { | ||
const styles = { | ||
myClass: 'my class', | ||
}; | ||
expect(classNames(styles, 'myClass', 'myClass')) | ||
.toBe(`${styles.myClass}`); | ||
}); | ||
|
||
it('should handle object of classes', () => { | ||
const styles = { | ||
myClass: 'my class', | ||
myOtherClass: 'my other class', | ||
}; | ||
const switches = { | ||
myClass: true, | ||
myOtherClass: true, | ||
}; | ||
expect(classNames(styles, switches)) | ||
.toBe(`${styles.myClass} ${styles.myOtherClass}`); | ||
}); | ||
|
||
it('should handle object with some classes switched off', () => { | ||
const styles = { | ||
myClass: 'my class', | ||
myOtherClass: 'my other class', | ||
}; | ||
const switches = { | ||
myClass: true, | ||
myOtherClass: false, | ||
}; | ||
expect(classNames(styles, switches)) | ||
.toBe(`${styles.myClass}`); | ||
}); | ||
|
||
it('should handle multiple input types', () => { | ||
const styles = { | ||
myClass: 'my class', | ||
myOtherClass: 'my other class', | ||
1: 'uno', | ||
stringClass: 'string class', | ||
arrayItemOne: 'array one', | ||
arrayItemTwo: 'array two', | ||
}; | ||
const switches = { | ||
myClass: true, | ||
myOtherClass: true, | ||
}; | ||
expect(classNames( | ||
styles, | ||
'stringClass', | ||
1, | ||
['arrayItemOne', 'arrayItemTwo'], | ||
switches, | ||
)) | ||
.toBe(`${styles.stringClass} ${styles[1]} ${styles.arrayItemOne} ${styles.arrayItemTwo} ${styles.myClass} ${styles.myOtherClass}`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters