Sign up (with export icon)

Testing helpers

Contribute to this guide Show the table of contents

The _getModelData() and _setModelData() functions exposed by model developer utilities and view developer utilities are useful development helpers.

They allow for “stringifying” the model and view structures, selections, ranges, and positions as well as for loading them from a string. They are often used when writing tests.

Note

Both tools are designed for prototyping, debugging, and testing purposes. Do not use them in production-grade code.

For instance, to take a peek at the editor model, you could use the _getModelData() helper:

import { _getModelData } from 'ckeditor5';

// More imports.
// ...

ClassicEditor
	.create( '<p>Hello <b>world</b>!</p>' )
	.then( editor => {
		console.log( _getModelData( editor.model ) );
		// -> '<paragraph>[]Hello <$text bold="true">world</$text>!</paragraph>'
	} );
Copy code

See the helper documentation to learn more about useful options.