@@ -11,18 +11,17 @@ import { setupImporting } from "./util/setupImporting";
11
11
12
12
@suite ( "Attribute container" )
13
13
export class AttributeContainerTest extends BEMProcessor {
14
- assertError ( errorType : typeof cssBlocks . CssBlockError , message : string , promise : postcss . LazyResult ) {
15
- return promise . then (
16
- ( ) => {
17
- assert ( false , `Error ${ errorType . name } was not raised.` ) ;
18
- } ,
19
- ( reason ) => {
20
- assert ( reason instanceof errorType , reason . toString ( ) ) ;
21
- assert . deepEqual ( reason . message , message ) ;
22
- } ) ;
14
+ async assertError ( errorType : typeof cssBlocks . CssBlockError , message : string , promise : postcss . LazyResult ) {
15
+ try {
16
+ await promise ;
17
+ assert ( false , `Error ${ errorType . name } was not raised.` ) ;
18
+ } catch ( reason ) {
19
+ assert ( reason instanceof errorType , reason . toString ( ) ) ;
20
+ assert . deepEqual ( reason . message , message ) ;
21
+ }
23
22
}
24
23
25
- @test "finds boolean attributes" ( ) {
24
+ @test async "finds boolean attributes" ( ) {
26
25
let { imports, importer, config, factory } = setupImporting ( ) ;
27
26
let filename = "foo/bar/a-block.css" ;
28
27
imports . registerSource (
@@ -32,22 +31,21 @@ export class AttributeContainerTest extends BEMProcessor {
32
31
.foo[state|small] { font-size: 5px; }` ,
33
32
) ;
34
33
35
- return factory . getBlock ( importer . identifier ( null , filename , config ) ) . then ( block => {
36
- let attr = block . rootClass . getAttributeValue ( "[state|large]" ) ;
37
- typedAssert . isNotNull ( attr ) . and ( ( attr ) => {
38
- assert . equal ( attr . isPresenceRule , true ) ;
39
- } ) ;
40
- let classObj = block . getClass ( "foo" ) ;
41
- typedAssert . isNotNull ( classObj ) . and ( classObj => {
42
- let classAttr = classObj . getAttributeValue ( "[state|small]" ) ;
43
- typedAssert . isNotNull ( classAttr ) . and ( classAttr => {
44
- assert . equal ( classAttr . isPresenceRule , true ) ;
45
- } ) ;
34
+ let block = await factory . getBlock ( importer . identifier ( null , filename , config ) ) ;
35
+ let attr = block . rootClass . getAttributeValue ( "[state|large]" ) ;
36
+ typedAssert . isNotNull ( attr ) . and ( ( attr ) => {
37
+ assert . equal ( attr . isPresenceRule , true ) ;
38
+ } ) ;
39
+ let classObj = block . getClass ( "foo" ) ;
40
+ typedAssert . isNotNull ( classObj ) . and ( classObj => {
41
+ let classAttr = classObj . getAttributeValue ( "[state|small]" ) ;
42
+ typedAssert . isNotNull ( classAttr ) . and ( classAttr => {
43
+ assert . equal ( classAttr . isPresenceRule , true ) ;
46
44
} ) ;
47
45
} ) ;
48
46
}
49
47
50
- @test "finds attribute groups" ( ) {
48
+ @test async "finds attribute groups" ( ) {
51
49
let { imports, importer, config, factory } = setupImporting ( ) ;
52
50
let filename = "foo/bar/a-block.css" ;
53
51
imports . registerSource (
@@ -59,26 +57,24 @@ export class AttributeContainerTest extends BEMProcessor {
59
57
.foo[state|mode=minimized] { display: block; max-height: 100px; }
60
58
.foo[state|mode=expanded] { display: block; }` ,
61
59
) ;
62
-
63
- return factory . getBlock ( importer . identifier ( null , filename , config ) ) . then ( block => {
64
- let sizeGroup : Array < AttrValue > = block . rootClass . getAttributeValues ( "[state|size]" ) ;
65
- assert . equal ( sizeGroup . length , 2 ) ;
66
- assert . includeMembers ( sizeGroup . map ( s => s . value ) , [ "large" , "small" ] ) ;
67
- let attrGroup : Array < AttrValue > = block . rootClass . getAttributeValues ( "[state|size]" , "large" ) ;
68
- assert . equal ( attrGroup . length , 1 ) ;
69
- assert . includeMembers ( attrGroup . map ( s => s . value ) , [ "large" ] ) ;
70
- let missingGroup : Array < AttrValue > = block . rootClass . getAttributeValues ( "[state|asdf]" ) ;
71
- assert . equal ( missingGroup . length , 0 ) ;
72
- let noAttr : Array < AttrValue > = block . rootClass . getAttributeValues ( "[state|size]" , "tiny" ) ;
73
- assert . equal ( noAttr . length , 0 ) ;
74
- typedAssert . isNotNull ( block . getClass ( "foo" ) ) . and ( classObj => {
75
- let modeGroup : Array < AttrValue > = classObj . getAttributeValues ( "[state|mode]" ) ;
76
- assert . equal ( modeGroup . length , 3 ) ;
77
- assert . includeMembers ( modeGroup . map ( s => s . value ) , [ "collapsed" , "minimized" , "expanded" ] ) ;
78
- } ) ;
60
+ let block = await factory . getBlock ( importer . identifier ( null , filename , config ) ) ;
61
+ let sizeGroup : Array < AttrValue > = block . rootClass . getAttributeValues ( "[state|size]" ) ;
62
+ assert . equal ( sizeGroup . length , 2 ) ;
63
+ assert . includeMembers ( sizeGroup . map ( s => s . value ) , [ "large" , "small" ] ) ;
64
+ let attrGroup : Array < AttrValue > = block . rootClass . getAttributeValues ( "[state|size]" , "large" ) ;
65
+ assert . equal ( attrGroup . length , 1 ) ;
66
+ assert . includeMembers ( attrGroup . map ( s => s . value ) , [ "large" ] ) ;
67
+ let missingGroup : Array < AttrValue > = block . rootClass . getAttributeValues ( "[state|asdf]" ) ;
68
+ assert . equal ( missingGroup . length , 0 ) ;
69
+ let noAttr : Array < AttrValue > = block . rootClass . getAttributeValues ( "[state|size]" , "tiny" ) ;
70
+ assert . equal ( noAttr . length , 0 ) ;
71
+ typedAssert . isNotNull ( block . getClass ( "foo" ) ) . and ( classObj => {
72
+ let modeGroup : Array < AttrValue > = classObj . getAttributeValues ( "[state|mode]" ) ;
73
+ assert . equal ( modeGroup . length , 3 ) ;
74
+ assert . includeMembers ( modeGroup . map ( s => s . value ) , [ "collapsed" , "minimized" , "expanded" ] ) ;
79
75
} ) ;
80
76
}
81
- @test "resolves inherited attribute groups" ( ) {
77
+ @test async "resolves inherited attribute groups" ( ) {
82
78
let { imports, importer, config, factory } = setupImporting ( ) ;
83
79
let filename = "foo/bar/sub-block.block.css" ;
84
80
imports . registerSource (
@@ -98,20 +94,19 @@ export class AttributeContainerTest extends BEMProcessor {
98
94
.foo[state|mode=minimized] { display: block; max-height: 200px; }` ,
99
95
) ;
100
96
101
- return factory . getBlock ( importer . identifier ( null , filename , config ) ) . then ( block => {
102
- let sizeGroup = block . rootClass . resolveAttributeValues ( "[state|size]" ) ;
103
- assert . equal ( sizeGroup . size , 3 ) ;
104
- assert . includeMembers ( [ ...sizeGroup . keys ( ) ] , [ "large" , "small" , "tiny" ] ) ;
105
- typedAssert . isNotNull ( block . getClass ( "foo" ) ) . and ( classObj => {
106
- let modeGroup = classObj . resolveAttributeValues ( "[state|mode]" ) ;
107
- assert . equal ( modeGroup . size , 3 ) ;
108
- typedAssert . isDefined ( modeGroup ) . and ( modeGroup => {
109
- typedAssert . isDefined ( modeGroup . get ( "collapsed" ) ) . and ( attr => {
110
- assert . equal ( attr . block , block . base ) ;
111
- } ) ;
112
- typedAssert . isDefined ( modeGroup . get ( "minimized" ) ) . and ( attr => {
113
- assert . equal ( attr . block , block ) ;
114
- } ) ;
97
+ let block = await factory . getBlock ( importer . identifier ( null , filename , config ) ) ;
98
+ let sizeGroup = block . rootClass . resolveAttributeValues ( "[state|size]" ) ;
99
+ assert . equal ( sizeGroup . size , 3 ) ;
100
+ assert . includeMembers ( [ ...sizeGroup . keys ( ) ] , [ "large" , "small" , "tiny" ] ) ;
101
+ typedAssert . isNotNull ( block . getClass ( "foo" ) ) . and ( classObj => {
102
+ let modeGroup = classObj . resolveAttributeValues ( "[state|mode]" ) ;
103
+ assert . equal ( modeGroup . size , 3 ) ;
104
+ typedAssert . isDefined ( modeGroup ) . and ( modeGroup => {
105
+ typedAssert . isDefined ( modeGroup . get ( "collapsed" ) ) . and ( attr => {
106
+ assert . equal ( attr . block , block . base ) ;
107
+ } ) ;
108
+ typedAssert . isDefined ( modeGroup . get ( "minimized" ) ) . and ( attr => {
109
+ assert . equal ( attr . block , block ) ;
115
110
} ) ;
116
111
} ) ;
117
112
} ) ;
0 commit comments