This repository was archived by the owner on Feb 4, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +38
-19
lines changed Expand file tree Collapse file tree 3 files changed +38
-19
lines changed Original file line number Diff line number Diff line change @@ -32,19 +32,20 @@ module.exports = class BemEntityName {
32
32
}
33
33
34
34
const data = this . _data = { block : obj . block } ;
35
- const modName = ( typeof obj . mod === 'string' ? obj . mod : obj . mod && obj . mod . name ) || obj . modName ;
36
35
37
36
obj . elem && ( data . elem = obj . elem ) ;
38
37
39
- if ( modName ) {
40
- const modVal = obj . hasOwnProperty ( 'modVal' ) || obj . mod && obj . mod . hasOwnProperty ( 'val' )
41
- ? obj . mod && obj . mod . val || obj . modVal
42
- : true ;
38
+ const modObj = obj . mod ;
39
+ const modName = ( typeof modObj === 'string' ? modObj : modObj && modObj . name ) || obj . modName ;
40
+ const hasModVal = modObj && modObj . hasOwnProperty ( 'val' ) || obj . hasOwnProperty ( 'modVal' ) ;
43
41
42
+ if ( modName ) {
44
43
data . mod = {
45
44
name : modName ,
46
- val : modVal
45
+ val : hasModVal ? modObj && modObj . val || obj . modVal : true
47
46
} ;
47
+ } else if ( modObj || hasModVal ) {
48
+ throw new Error ( 'This is not valid BEM entity: the field `mod.name` is undefined.' ) ;
48
49
}
49
50
}
50
51
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ const test = require ( 'ava' ) ;
2
+
3
+ const BemEntityName = require ( '../index' ) ;
4
+
5
+ test ( 'should throw error for if entity object is not valid' , t => {
6
+ t . throws (
7
+ ( ) => new BemEntityName ( { elem : 'elem' } ) ,
8
+ 'This is not valid BEM entity: the field `block` is undefined.'
9
+ ) ;
10
+ } ) ;
11
+
12
+ test ( 'should throw error for if mod object is empty' , t => {
13
+ t . throws (
14
+ ( ) => new BemEntityName ( { block : 'block' , mod : { } } ) ,
15
+ 'This is not valid BEM entity: the field `mod.name` is undefined.'
16
+ ) ;
17
+ } ) ;
18
+
19
+ test ( 'should throw error for if mod name is undefined' , t => {
20
+ t . throws (
21
+ ( ) => new BemEntityName ( { block : 'block' , mod : { val : 'val' } } ) ,
22
+ 'This is not valid BEM entity: the field `mod.name` is undefined.'
23
+ ) ;
24
+ } ) ;
25
+
26
+ test ( 'should throw error for if modName is undefined' , t => {
27
+ t . throws (
28
+ ( ) => new BemEntityName ( { block : 'block' , modVal : 'val' } ) ,
29
+ 'This is not valid BEM entity: the field `mod.name` is undefined.'
30
+ ) ;
31
+ } ) ;
You can’t perform that action at this time.
0 commit comments