|
@@ -260,6 +260,33 @@ describe( 'Element', () => {
|
|
|
el = new ViewElement( 'p' );
|
|
el = new ViewElement( 'p' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ describe( 'setAttribute', () => {
|
|
|
|
|
+ it( 'should set attribute', () => {
|
|
|
|
|
+ el.setAttribute( 'foo', 'bar' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( el._attrs.has( 'foo' ) ).to.be.true;
|
|
|
|
|
+ expect( el._attrs.get( 'foo' ) ).to.equal( 'bar' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should set class', () => {
|
|
|
|
|
+ el.setAttribute( 'class', 'foo bar' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( el._attrs.has( 'class' ) ).to.be.false;
|
|
|
|
|
+ expect( el._classes.has( 'foo' ) ).to.be.true;
|
|
|
|
|
+ expect( el._classes.has( 'bar' ) ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should replace all existing classes', () => {
|
|
|
|
|
+ el.setAttribute( 'class', 'foo bar baz' );
|
|
|
|
|
+ el.setAttribute( 'class', 'qux' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( el._classes.has( 'foo' ) ).to.be.false;
|
|
|
|
|
+ expect( el._classes.has( 'bar' ) ).to.be.false;
|
|
|
|
|
+ expect( el._classes.has( 'baz' ) ).to.be.false;
|
|
|
|
|
+ expect( el._classes.has( 'qux' ) ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
describe( 'getAttribute', () => {
|
|
describe( 'getAttribute', () => {
|
|
|
it( 'should return attribute', () => {
|
|
it( 'should return attribute', () => {
|
|
|
el.setAttribute( 'foo', 'bar' );
|
|
el.setAttribute( 'foo', 'bar' );
|
|
@@ -276,6 +303,12 @@ describe( 'Element', () => {
|
|
|
expect( el.hasAttribute( 'foo' ) ).to.be.true;
|
|
expect( el.hasAttribute( 'foo' ) ).to.be.true;
|
|
|
expect( el.hasAttribute( 'bom' ) ).to.be.false;
|
|
expect( el.hasAttribute( 'bom' ) ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should return true if element has class attribute', () => {
|
|
|
|
|
+ expect( el.hasAttribute( 'class' ) ).to.be.false;
|
|
|
|
|
+ el.addClass( 'foo' );
|
|
|
|
|
+ expect( el.hasAttribute( 'class' ) ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'getAttributeKeys', () => {
|
|
describe( 'getAttributeKeys', () => {
|
|
@@ -293,6 +326,18 @@ describe( 'Element', () => {
|
|
|
|
|
|
|
|
expect( i ).to.equal( 2 );
|
|
expect( i ).to.equal( 2 );
|
|
|
} );
|
|
} );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should return class key', () => {
|
|
|
|
|
+ el.addClass( 'foo' );
|
|
|
|
|
+ el.setAttribute( 'bar', true );
|
|
|
|
|
+ const expected = [ 'class', 'bar' ];
|
|
|
|
|
+ let i = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for ( let key of el.getAttributeKeys() ) {
|
|
|
|
|
+ expect( key ).to.equal( expected[ i ] );
|
|
|
|
|
+ i++;
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'removeAttribute', () => {
|
|
describe( 'removeAttribute', () => {
|