11var test = require ( 'tape' )
22var concat = require ( 'simple-concat' )
3+ var through = require ( 'through2' )
34var hyperstream = require ( '../' )
45
56test ( 'add an attribute' , function ( t ) {
@@ -26,6 +27,18 @@ test('replace an attribute', function (t) {
2627 hs . end ( '<div class="it did not work" id="a"></div>' )
2728} )
2829
30+ test ( 'remove attribute' , function ( t ) {
31+ var hs = hyperstream ( {
32+ '#a' : { class : null }
33+ } )
34+ concat ( hs , function ( err , result ) {
35+ t . ifError ( err )
36+ t . equal ( result + '' , '<div id="a"></div>' )
37+ t . end ( )
38+ } )
39+ hs . end ( '<div class="it did not work" id="a"></div>' )
40+ } )
41+
2942test ( 'prepend to attribute' , function ( t ) {
3043 var hs = hyperstream ( {
3144 '#a' : { class : { prepend : 'it ' } }
@@ -49,3 +62,41 @@ test('append to attribute', function (t) {
4962 } )
5063 hs . end ( '<div class="it" id="a"></div>' )
5164} )
65+
66+ test ( 'edit attribute' , function ( t ) {
67+ var hs = hyperstream ( {
68+ '#a' : {
69+ class : function ( original ) {
70+ return original . toUpperCase ( )
71+ }
72+ }
73+ } )
74+ concat ( hs , function ( err , result ) {
75+ t . ifError ( err )
76+ t . equal ( result + '' , '<div class="CLASSNAME" id=a></div>' )
77+ t . end ( )
78+ } )
79+ hs . end ( '<div class="classname" id=a></div>' )
80+ } )
81+
82+ test ( 'edit attribute with streams' , function ( t ) {
83+ var hs = hyperstream ( {
84+ '#a' : {
85+ class : function ( initial ) {
86+ var stream = through ( function ( chunk , enc , cb ) {
87+ cb ( )
88+ } , function ( cb ) {
89+ cb ( null , 'beep boop' )
90+ } )
91+ stream . end ( initial )
92+ return stream
93+ }
94+ }
95+ } )
96+ concat ( hs , function ( err , result ) {
97+ t . ifError ( err )
98+ t . equal ( result + '' , '<div class="beep boop" id=a></div>' )
99+ t . end ( )
100+ } )
101+ hs . end ( '<div class="classname" id=a></div>' )
102+ } )
0 commit comments