Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should return an empty array if a given node does not have nodes of a given `nodeType`', () => {
const { state } = createEditor(doc(p('')));
const result = findChildrenByNode({ node: state.doc, type: state.schema.nodes.table });
expect(result.length).toEqual(0);
});
it('returns false when no active selection', () => {
const { state, schema } = createEditor(doc(p('Something', em('is italic'))));
expect(getMarkRange(state.selection.$from, schema.marks.em)).toBeFalse();
});
it('should transform complex content', () => {
const plugin = markPasteRule({ regexp: /(@[a-z]+)/, type: testSchema.marks.strong });
createEditor(doc(p('')), { plugins: [plugin] })
.paste(doc(p('Some @test @content'), p('should @be amazing')))
.callback(content => {
expect(content.doc).toEqualProsemirrorNode(
doc(
p('Some ', strong('@test'), ' ', strong('@content')),
p('should ', strong('@be'), ' amazing'),
p(''),
),
);
});
});
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('returns false when neither text nor state has change', () => {
const {
state: { tr },
view,
} = createEditor(doc(p('inline'), p('aba', 'awesome')));
view.dispatch(tr);
expect(transactionChanged(tr)).toBeFalse();
});
it('should ignore matches when called', () => {
const handlers = {
onExit: jest.fn(
({ addIgnored, range: { from }, suggester: { char, name } }: SuggestExitHandlerParams) => {
addIgnored({ from, char, name });
},
),
onChange: jest.fn(),
};
const plugin = suggest({ char: '@', name: 'at', ...handlers });
createEditor(doc(p('')), { plugins: [plugin] })
.insertText('@abc ')
.callback(() => {
expect(handlers.onExit).toHaveBeenCalledTimes(1);
expect(handlers.onChange).toHaveBeenCalledTimes(4);
jest.clearAllMocks();
})
.backspace(3)
.callback(() => expect(handlers.onChange).not.toHaveBeenCalled());
});