瀏覽代碼

Added attributes sorting to view test utils.

Szymon Kupś 9 年之前
父節點
當前提交
ac1dc56135

+ 2 - 2
packages/ckeditor5-engine/tests/_utils-tests/view.js

@@ -118,7 +118,7 @@ describe( 'view test utils', () => {
 			expect( stringify( p ) ).to.equal( '<p><b>foobar</b></p>' );
 		} );
 
-		it( 'should write elements with attributes', () => {
+		it( 'should write elements with attributes (attributes in alphabetical order)', () => {
 			const text = new Text( 'foobar' );
 			const b = new Element( 'b', {
 				foo: 'bar'
@@ -129,7 +129,7 @@ describe( 'view test utils', () => {
 				class: 'short wide'
 			}, b );
 
-			expect( stringify( p ) ).to.equal( '<p class="short wide" baz="qux" bar="taz"><b foo="bar">foobar</b></p>' );
+			expect( stringify( p ) ).to.equal( '<p bar="taz" baz="qux" class="short wide"><b foo="bar">foobar</b></p>' );
 		} );
 
 		it( 'should write selection ranges inside elements', () => {

+ 2 - 1
packages/ckeditor5-engine/tests/_utils/view.js

@@ -913,8 +913,9 @@ class ViewStringify {
 	 */
 	_stringifyElementAttributes( element ) {
 		const attributes = [];
+		const keys = [ ...element.getAttributeKeys() ].sort();
 
-		for ( let attribute of element.getAttributeKeys() ) {
+		for ( let attribute of keys ) {
 			attributes.push( `${ attribute }="${ element.getAttribute( attribute ) }"` );
 		}