@@ -30,81 +30,92 @@ describe('Class Sink', () => {
3030
3131 describe ( 'Given a class object' , ( ) => {
3232
33- it ( 'sets classes for truthy attributes on sink' , ( ) => {
34- const el = MockElement ( ) ;
35- const sink = ClassObjectSink ( < HTMLElement > el ) ;
33+ describe ( 'when a property of the object is a present value' , ( ) => {
34+
35+ it ( 'sets classes for truthy attributes on sink' , ( ) => {
36+ const el = MockElement ( ) ;
37+ const sink = ClassObjectSink ( < HTMLElement > el ) ;
38+
39+ sink ( {
40+ class1 : true ,
41+ class2 : 1 ,
42+ class3 : 'yes!' ,
43+ } ) ;
44+ expect ( el . className ) . toContain ( 'class1' ) ;
45+ expect ( el . className ) . toContain ( 'class2' ) ;
46+ expect ( el . className ) . toContain ( 'class3' ) ;
47+ } ) ;
3648
37- sink ( {
38- class1 : true ,
39- class2 : 1 ,
40- class3 : 'yes!' ,
49+ it ( 'clears classes for falsy attributes on sink' , ( ) => {
50+ const el = MockElement ( { className : 'class1 class2 class3' } ) ;
51+ const sink = ClassObjectSink ( < HTMLElement > el ) ;
52+ expect ( el . className ) . toContain ( 'class1' ) ;
53+ expect ( el . className ) . toContain ( 'class2' ) ;
54+ expect ( el . className ) . toContain ( 'class3' ) ;
55+
56+ sink ( {
57+ class1 : false ,
58+ class2 : 0 ,
59+ class3 : '' ,
60+ } ) ;
61+ expect ( el . className ) . not . toContain ( 'class1' ) ;
62+ expect ( el . className ) . not . toContain ( 'class2' ) ;
63+ expect ( el . className ) . not . toContain ( 'class3' ) ;
4164 } ) ;
42- expect ( el . className ) . toContain ( 'class1' ) ;
43- expect ( el . className ) . toContain ( 'class2' ) ;
44- expect ( el . className ) . toContain ( 'class3' ) ;
45- } ) ;
4665
47- it ( 'clears classes for falsy attributes on sink' , ( ) => {
48- const el = MockElement ( { className : 'class1 class2 class3' } ) ;
49- const sink = ClassObjectSink ( < HTMLElement > el ) ;
50- expect ( el . className ) . toContain ( 'class1' ) ;
51- expect ( el . className ) . toContain ( 'class2' ) ;
52- expect ( el . className ) . toContain ( 'class3' ) ;
66+ it ( 'should not add class when value is false' , ( ) => {
67+ const el = MockElement ( ) ;
68+ const sink = ClassObjectSink ( < HTMLElement > el ) ;
5369
54- sink ( {
55- class1 : false ,
56- class2 : 0 ,
57- class3 : '' ,
70+ sink ( {
71+ dotted : false ,
72+ } ) ;
73+
74+ expect ( el . className ) . not . toContain ( 'dotted' ) ;
75+ expect ( el . className ) . toEqual ( '' ) ;
5876 } ) ;
59- expect ( el . className ) . not . toContain ( 'class1' ) ;
60- expect ( el . className ) . not . toContain ( 'class2' ) ;
61- expect ( el . className ) . not . toContain ( 'class3' ) ;
77+
6278 } ) ;
6379
64- it ( 'should not add class when value is false (promise resolved to false)' , ( ) => {
65- const el = MockElement ( ) ;
66- const sink = ClassObjectSink ( < HTMLElement > el ) ;
80+ describe ( 'when a property of the object is a future value' , ( ) => {
6781
68- // Simulating a promise that resolved to false
69- sink ( {
70- dotted : false ,
71- } ) ;
82+ describe ( 'when it resolves/emits false' , ( ) => {
7283
73- expect ( el . className ) . not . toContain ( 'dotted' ) ;
74- expect ( el . className ) . toEqual ( '' ) ;
75- } ) ;
84+ it ( 'should not add a class corresponding to the property name' , async ( ) => {
85+ const el = MockElement ( ) ;
86+ const sink = ClassObjectSink ( < HTMLElement > el ) ;
7687
77- it ( 'should not add class when promise resolves to false' , async ( ) => {
78- const el = MockElement ( ) ;
79- const sink = ClassObjectSink ( < HTMLElement > el ) ;
88+ const dottedPromise = Promise . resolve ( false ) ;
89+ sink ( {
90+ dotted : dottedPromise ,
91+ } ) ;
92+
93+ await dottedPromise ;
94+
95+ expect ( el . className ) . not . toContain ( 'dotted' ) ;
96+ expect ( el . className ) . toEqual ( '' ) ;
97+ } ) ;
8098
81- // Pass a promise that resolves to false
82- const dottedPromise = Promise . resolve ( false ) ;
83- sink ( {
84- dotted : dottedPromise ,
8599 } ) ;
86100
87- // Wait for the promise to resolve
88- await dottedPromise ;
101+ describe ( 'when it resolves/emits true' , ( ) => {
89102
90- expect ( el . className ) . not . toContain ( 'dotted' ) ;
91- expect ( el . className ) . toEqual ( '' ) ;
92- } ) ;
103+ it ( 'should add a class corresponding to the property name' , async ( ) => {
104+ const el = MockElement ( ) ;
105+ const sink = ClassObjectSink ( < HTMLElement > el ) ;
93106
94- it ( 'should add class when promise resolves to true' , async ( ) => {
95- const el = MockElement ( ) ;
96- const sink = ClassObjectSink ( < HTMLElement > el ) ;
107+ const activePromise = Promise . resolve ( true ) ;
108+ sink ( {
109+ active : activePromise ,
110+ } ) ;
97111
98- // Pass a promise that resolves to true
99- const activePromise = Promise . resolve ( true ) ;
100- sink ( {
101- active : activePromise ,
102- } ) ;
112+ await activePromise ;
103113
104- // Wait for the promise to resolve
105- await activePromise ;
114+ expect ( el . className ) . toContain ( 'active' ) ;
115+ } ) ;
116+
117+ } ) ;
106118
107- expect ( el . className ) . toContain ( 'active' ) ;
108119 } ) ;
109120
110121 } ) ;
0 commit comments