How to use the jest-prosemirror.createEditor function in jest-prosemirror

To help you get started, we’ve selected a few jest-prosemirror examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ifiokjr / remirror / @remirror / core-utils / src / __tests__ / prosemirror-node-utils.spec.ts View on Github external
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);
  });
github ifiokjr / remirror / @remirror / core-utils / src / __tests__ / dom-utils.spec.ts View on Github external
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();
  });
github ifiokjr / remirror / @remirror / core-utils / src / __tests__ / prosemirror-rules.spec.ts View on Github external
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(''),
          ),
        );
      });
  });
github ifiokjr / remirror / @remirror / core-utils / src / __tests__ / prosemirror-rules.spec.ts View on Github external
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')));
  });
});
github ifiokjr / remirror / @remirror / core-utils / src / __tests__ / prosemirror-utils.spec.ts View on Github external
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();
  });
github ifiokjr / remirror / packages / prosemirror-suggest / src / __tests__ / suggest-plugin.spec.ts View on Github external
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());
  });