@stesura/core/testing
Helpers for writing tests against the Stesura schema. Build documents with the tb builders and testDoc, which wraps content in a section and validates it against the schema.
Requires prosemirror-test-builder, an optional peer dependency that is not auto-installed: add it to your devDependencies. tempEditor mounts a real EditorView, so it needs a DOM (for example jsdom).
Functions & values
checkedDoc
Parameters:| Name | Type | Default |
|---|---|---|
doc | T |
colCount
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState |
collectAttr
Parameters:| Name | Type | Default |
|---|---|---|
doc | Node | |
attrName | string | |
predicate | (node: Node) => boolean |
findFirstInContent
Parameters:| Name | Type | Default |
|---|---|---|
doc | Node | |
typeName | string |
getAllSections
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState |
getCommentAttrs
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState |
getCursorSection
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState |
getTableNode
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState |
make2x2State
Parameters:make3x3State
Parameters:makeCell
Parameters:| Name | Type | Default |
|---|---|---|
colwidth | number |
makeCellWithText
Parameters:| Name | Type | Default |
|---|---|---|
text | string | |
colwidth | number |
makeLinkEditorState
Parameters:| Name | Type | Default |
|---|---|---|
doc | TaggedNode | |
from | number | |
to | number |
makeRow
Parameters:| Name | Type | Default |
|---|---|---|
cells | Node[] |
makeTable
Parameters:| Name | Type | Default |
|---|---|---|
rows | Node[] |
rowCount
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState |
selectionInContent
Parameters:| Name | Type | Default |
|---|---|---|
doc | Node |
singleSectionState
Parameters:| Name | Type | Default |
|---|---|---|
content | [attrsOrFirstChild?: ChildSpec | Attrs | undefined, ...children: ChildSpec[]] |
stateWithCursorAt
Parameters:| Name | Type | Default |
|---|---|---|
table | Node | |
rowIndex | number | |
colIndex | number |
stateWithSelectedImage
Parameters:| Name | Type | Default |
|---|---|---|
imageAttrs | Record<string, unknown> |
stateWithTable
Parameters:| Name | Type | Default |
|---|---|---|
table | Node |
tb
tempEditor
Parameters:| Name | Type | Default |
|---|---|---|
opts | { doc?: Node; plugins?: Plugin<any>[]; } |
testDoc
Parameters:| Name | Type | Default |
|---|---|---|
content | [attrsOrFirstChild?: ChildSpec | Attrs | undefined, ...children: ChildSpec[]] |
testSection
Parameters:| Name | Type | Default |
|---|---|---|
content | [attrsOrFirstChild?: ChildSpec | Attrs | undefined, ...children: ChildSpec[]] | |
attrs | Partial<SectionAttrs> |
twoSectionState
Parameters:uncheckedTestDoc
Parameters:| Name | Type | Default |
|---|---|---|
content | [attrsOrFirstChild?: ChildSpec | Attrs | undefined, ...children: ChildSpec[]] |
Types
TaggedNode
| Name | Type | Default |
|---|---|---|
type | NodeTypeThe type of node that this is. | |
attrs | AttrsAn object mapping attribute names to values. The kind of attributes allowed and required are determined by the node type. | |
marks | readonly Mark[]The marks (things like whether it is emphasized or part of a link) applied to this node. | |
content | FragmentA container holding the node’s children. | |
children | readonly Node[]The array of this node’s child nodes. | |
text | string | undefinedFor text nodes, this contains the node’s text content. | |
nodeSize | numberThe size of this node, as defined by the integer-based indexing scheme . For text nodes, this is the amount of characters. For other leaf nodes, it is one. For non-leaf nodes, it is the size of the content plus two (the start and end token). | |
childCount | numberThe number of children that the node has. | |
child | (index: number) => NodeGet the child node at the given index. Raises an error when the index is out of range. | |
maybeChild | (index: number) => Node | nullGet the child node at the given index, if it exists. | |
forEach | (f: (node: Node, offset: number, index: number) => void) => voidCall | |
nodesBetween | (from: number, to: number, f: (node: Node, pos: number, parent: Node | null, index: number) => boolean | void, startPos?: number | undefined) => voidInvoke a callback for all descendant nodes recursively overlapping the given two positions that are relative to start of this node’s content. This includes all ancestors of the nodes containing the two positions. The callback is invoked with the node, its position relative to the original node (method receiver), its parent node, and its child index. When the callback returns false for a given node, that node’s children will not be recursed over. The last parameter can be used to specify a starting position to count from. | |
descendants | (f: (node: Node, pos: number, parent: Node | null, index: number) => boolean | void) => voidCall the given callback for every descendant node. Doesn’t
descend into a node when the callback returns | |
textContent | stringConcatenates all the text nodes found in this fragment and its children. | |
textBetween | (from: number, to: number, blockSeparator?: string | null | undefined, leafText?: string | ((leafNode: Node) => string) | null | undefined) => stringGet all text between positions | |
firstChild | Node | nullReturns this node’s first child, or | |
lastChild | Node | nullReturns this node’s last child, or | |
eq | (other: Node) => booleanTest whether two nodes represent the same piece of document. | |
sameMarkup | (other: Node) => booleanCompare the markup (type, attributes, and marks) of this node to
those of another. Returns | |
hasMarkup | (type: NodeType, attrs?: Attrs | null | undefined, marks?: readonly Mark[] | undefined) => booleanCheck whether this node’s markup correspond to the given type, attributes, and marks. | |
copy | (content?: Fragment | null | undefined) => NodeCreate a new node with the same markup as this node, containing the given content (or empty, if no content is given). | |
mark | (marks: readonly Mark[]) => NodeCreate a copy of this node, with the given set of marks instead of the node’s own marks. | |
cut | (from: number, to?: number | undefined) => NodeCreate a copy of this node with only the content between the
given positions. If | |
slice | (from: number, to?: number | undefined, includeParents?: boolean | undefined) => SliceCut out the part of the document between the given positions, and
return it as a | |
replace | (from: number, to: number, slice: Slice) => NodeReplace the part of the document between the given positions with
the given slice. The slice must ‘fit’, meaning its open sides
must be able to connect to the surrounding content, and its
content nodes must be valid children for the node they are placed
into. If any of this is violated, an error of type
| |
nodeAt | (pos: number) => Node | nullFind the node directly after the given position. | |
childAfter | (pos: number) => { node: Node | null; index: number; offset: number; }Find the (direct) child node after the given offset, if any, and return it along with its index and offset relative to this node. | |
childBefore | (pos: number) => { node: Node | null; index: number; offset: number; }Find the (direct) child node before the given offset, if any, and return it along with its index and offset relative to this node. | |
resolve | (pos: number) => ResolvedPosResolve the given position in the document, returning an object with information about its context. | |
rangeHasMark | (from: number, to: number, type: Mark | MarkType) => booleanTest whether a given mark or mark type occurs in this document between the two given positions. | |
isBlock | booleanTrue when this is a block (non-inline node) | |
isTextblock | booleanTrue when this is a textblock node, a block node with inline content. | |
inlineContent | booleanTrue when this node allows inline content. | |
isInline | booleanTrue when this is an inline node (a text node or a node that can appear among text). | |
isText | booleanTrue when this is a text node. | |
isLeaf | booleanTrue when this is a leaf node. | |
isAtom | booleanTrue when this is an atom, i.e. when it does not have directly
editable content. This is usually the same as | |
toString | () => stringReturn a string representation of this node for debugging purposes. | |
contentMatchAt | (index: number) => ContentMatchGet the content match in this node at the given index. | |
canReplace | (from: number, to: number, replacement?: Fragment | undefined, start?: number | undefined, end?: number | undefined) => booleanTest whether replacing the range between | |
canReplaceWith | (from: number, to: number, type: NodeType, marks?: readonly Mark[] | undefined) => booleanTest whether replacing the range | |
canAppend | (other: Node) => booleanTest whether the given node’s content could be appended to this node. If that node is empty, this will only return true if there is at least one node type that can appear in both nodes (to avoid merging completely incompatible nodes). | |
check | () => voidCheck whether this node and its descendants conform to the schema, and raise an exception when they do not. | |
toJSON | () => anyReturn a JSON-serializeable representation of this node. | |
tag | Record<string, number> |