Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('matches with a singular nodeType', () => {
expect(nodeEqualsType({ types: schema.nodes.paragraph, node: p() })).toBeTrue();
});
it('should wrap matched content with the specified node type', () => {
const getAttrs = jest.fn(() => ({ 'data-testid': 'awesome' }));
const rule = nodeInputRule({ regexp: /~([^~]+)~$/, type: testSchema.nodes.horizontalRule, getAttrs });
const {
state: { selection },
view,
} = createEditor(doc(p('~Hello')), { rules: [rule] });
const { from, to } = selection;
const params = [view, from, to, '~'];
view.someProp('handleTextInput', f => {
f(...params);
});
expect(view.state.doc).toEqualProsemirrorNode(doc(horizontalRule(), p()));
expect(getAttrs).toHaveBeenCalledWith(expect.arrayContaining(['~Hello~', 'Hello']));
});
it('matches with an array of nodeTypes', () => {
const { paragraph, blockquote: bq } = schema.nodes;
expect(nodeEqualsType({ types: [paragraph, bq], node: blockquote() })).toBeTrue();
});
});
it('should not give false positives', () => {
const rule = nodeInputRule({ regexp: /~([^~]+)~$/, type: testSchema.nodes.horizontalRule });
const {
state: { selection },
view,
} = createEditor(doc(p('~Hello')), { rules: [rule] });
const { from, to } = selection;
const params = [view, from, to, '@'];
view.someProp('handleTextInput', f => {
const value = f(...params);
expect(value).toBe(false);
return value;
});
expect(view.state.doc).toEqualProsemirrorNode(doc(p('~Hello')));
});
});
it('adds the node wrapping the selection', () => {
const from = doc(p('Wrap ', 'me'));
const to = doc(blockquote(p('Wrap me')));
expect(toggleWrap(schema.nodes.blockquote)).toTransformNode({ from, to });
});
it('replaces valid content', () => {
const from = doc(p('replace me'));
const to = doc(p('replace ', atomInline()));
expect(replaceText({ appendText: '', type: schema.nodes.atomInline })).toTransformNode({ from, to });
});