Ver código fonte

Tests: Tests for options param in `getData()`.

Krzysztof Krztoń 7 anos atrás
pai
commit
30fa9107fb

+ 22 - 0
packages/ckeditor5-core/tests/editor/utils/dataapimixin.js

@@ -8,6 +8,7 @@ import Editor from '../../../src/editor/editor';
 import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 describe( 'DataApiMixin', () => {
 	let editor;
@@ -40,6 +41,9 @@ describe( 'DataApiMixin', () => {
 	} );
 
 	describe( 'getData()', () => {
+
+		testUtils.createSinonSandbox();
+
 		it( 'should be added to editor interface', () => {
 			expect( editor ).have.property( 'getData' ).to.be.a( 'function' );
 		} );
@@ -49,5 +53,23 @@ describe( 'DataApiMixin', () => {
 
 			expect( editor.getData() ).to.equal( 'foo' );
 		} );
+
+		it( 'should get data of the second root', () => {
+			setData( editor.model, 'bar', { rootName: 'secondRoot' } );
+
+			expect( editor.getData( { rootName: 'secondRoot' } ) ).to.equal( 'bar' );
+		} );
+
+		it( 'should pass options object to data.get() method internally', () => {
+			const spy = testUtils.sinon.spy( editor.data, 'get' );
+			const options = { rootName: 'main', trim: 'none' };
+
+			setData( editor.model, 'foo' );
+
+			expect( editor.getData( options ) ).to.equal( 'foo' );
+
+			testUtils.sinon.assert.calledOnce( spy );
+			testUtils.sinon.assert.calledWith( spy, options );
+		} );
 	} );
 } );