@yosu/jest-slate-model
v0.1.0
Published
A custom matcher and editor initializer for slatejs.
Downloads
12
Readme
jest-slate-model
Introduction
This package provide a unit test utility for Slate. You can test slate model with selection embbeded format.
Slate model is flexible but difficult to read especially it has a selection.
For example, select world in the hello world! is:
const editor = {
children: [
type: "paragraph",
children: [{ text: "hello world!" }],
],
selection: {
anchor: { path: [0, 0], offset: 6 }
focus: { path: [0, 0], offset: 11 }
}
}
You can write the test of the same editor state as below:
import { createEditor } from '@yosu/jest-slate-model';
test("Test", () => {
const editor = createEditor([{
type: "paragraph",
children: [{ text: "hello <anchor>world<focus>!" }],
}]);
expect(editor).toMatchEditorState([{
type: "paragraph",
children: [{ text: "hello <anchor>world<focus>!" }],
}])
});If anchor and focus is the same position, use <cursor> instead.
Install
This library is available as a package on NPM, install with your favorite package manager:
npm install --save-dev @yosu/jest-slate-modelQuick start
Import @yosu/jest-slate-model/matcher once in your tests setup file:
// In your custom-matcher.js (or any other name)
import '@yosu/jest-slate-model/matcher';
// In jest.config.js add (if you haven't already)
setupFilesAfterEnv: ['<rootDir>/custom-matcher.js']Lisence
This project is licensed under the MIT License, see the LICENSE.txt file for details.
