How to use the jest-prosemirror.pmBuild 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 / extension-code-block / src / __tests__ / code-block.spec.ts View on Github external
describe('schema', () => {
  const { schema } = createBaseTestManager([{ extension: new CodeBlockExtension(), priority: 1 }]);
  const attrs = { language: 'typescript' };
  const content = 'unchanged without decorations';

  const { codeBlock, doc } = pmBuild(schema, {
    codeBlock: { nodeType: 'codeBlock', ...attrs },
  });

  it('creates the correct dom node', () => {
    expect(toHTML({ node: codeBlock(content), schema })).toBe(
      `<pre class="language-${attrs.language}"><code data-code-block-language="${attrs.language}">${content}</code></pre>`,
    );
  });

  it('parses the dom structure and finds itself', () =&gt; {
    const node = fromHTML({
      schema,
      content: `<pre><code data-code-block-language="${attrs.language}" class="language-${attrs.language}">${content}</code></pre>`,
    });
    const expected = doc(codeBlock(content));
    expect(node).toEqualProsemirrorNode(expected);
github ifiokjr / remirror / @remirror / core-extensions / src / marks / __tests__ / link-extension.spec.ts View on Github external
it('parses extra attributes', () =&gt; {
      const { a, doc, p } = pmBuild(schema, {
        a: { markType: 'link', href, custom, title },
      });

      const node = fromHTML({
        content: `<p><a data-custom="${custom}" title="${title}" href="${href}">link</a></p>`,
        schema,
      });

      const expected = doc(p(a('link')));
      expect(node).toEqualProsemirrorNode(expected);
    });
  });
github ifiokjr / remirror / @remirror / core-extensions / src / nodes / paragraph / __tests__ / paragraph-extension.spec.ts View on Github external
it('it produces valid html', () =&gt; {
    ({ schema } = createBaseTestManager([{ extension: new ParagraphExtension(), priority: 1 }]));
    ({ doc, p } = pmBuild(schema, {
      p: { nodeType: 'paragraph', indent: 1, align: 'right', lineSpacing: '100%', id: 'never' },
    }));
    const html = toHTML({
      node: p('hello'),
      schema,
    });
    expect(html).toBe(`<p id="never" data-indent="1" style="text-align: right;line-height: 100%;">hello</p>`);
  });
});
github ifiokjr / remirror / @remirror / extension-mention / src / __tests__ / mention.spec.ts View on Github external
describe('schema', () =&gt; {
  const { schema } = createBaseTestManager([{ extension: new MentionExtension(), priority: 1 }]);
  const attrs = { id: 'test', label: '@test', name: 'testing' };

  const { mention, p, doc } = pmBuild(schema, {
    mention: { markType: 'mention', ...attrs },
  });

  it('creates the correct dom node', () =&gt; {
    expect(toHTML({ node: p(mention(attrs.label)), schema })).toMatchInlineSnapshot(`
      <p>
        <a data-mention-name="testing" data-mention-id="test" class="mention mention-testing">
          @test
        </a>
      </p>
    `);
  });
github ifiokjr / remirror / @remirror / core / src / __tests__ / node-extension.spec.ts View on Github external
{
      extension: new CustomExtension({
        extraAttrs: [
          'title',
          ['run', 'failure', 'data-run'],
          {
            default: 'yo',
            getAttrs: domNode =&gt; (domNode as Element).getAttribute('simple'),
            name: 'crazy',
          },
        ],
      }),
      priority: 1,
    },
  ]);
  const { doc, custom, other } = pmBuild(schema, {
    custom: { nodeType: 'custom', run, title, crazy: 'yo' },
    other: { nodeType: 'custom', run, title, crazy: 'believe me' },
  });

  it('creates attrs with the correct shape', () =&gt; {
    expect(schema.nodes.custom.spec.attrs).toEqual({
      title: { default: '' },
      run: { default: 'failure' },
      crazy: { default: 'yo' },
    });
  });

  it('parses the dom for extra attributes', () =&gt; {
    const node = fromHTML({
      content: `<p data-run="${run}" title="${title}">hello</p>`,
      schema,
github ifiokjr / remirror / @remirror / core-extensions / src / nodes / __tests__ / heading-extension.spec.ts View on Github external
describe('schema', () =&gt; {
  const { schema } = createBaseTestManager([{ extension: new HeadingExtension(), priority: 1 }]);
  const { h1, h2, h3, doc } = pmBuild(schema, {
    h1: { nodeType: 'heading' },
    h2: { nodeType: 'heading', level: 2 },
    h3: { nodeType: 'heading', level: 3 },
  });

  it('defaults to level 1', () =&gt; {
    expect(toHTML({ node: h1('Heading'), schema })).toBe('<h1>Heading</h1>');
  });

  it('changes level based on attributes', () =&gt; {
    expect(toHTML({ node: h2('Heading'), schema })).toBe('<h2>Heading</h2>');
    expect(toHTML({ node: h3('Heading'), schema })).toBe('<h3>Heading</h3>');
  });

  it('it can parse content', () =&gt; {
    const node = fromHTML({ content: '<h2>Hello</h2>', schema });
github ifiokjr / remirror / @remirror / core-extensions / src / nodes / paragraph / __tests__ / paragraph-extension.spec.ts View on Github external
describe('schema', () =&gt; {
  let { schema } = createBaseTestManager([{ extension: new ParagraphExtension(), priority: 1 }]);
  let { doc, p } = pmBuild(schema, {});

  it('it can parse content', () =&gt; {
    ({ schema } = createBaseTestManager([{ extension: new ParagraphExtension(), priority: 1 }]));
    ({ doc, p } = pmBuild(schema, {
      p: { nodeType: 'paragraph', indent: 1, align: 'right', lineSpacing: '100%', id: 'never' },
    }));
    const node = fromHTML({
      content: `<p id="never" style="text-align: right; line-height: 100%;" data-indent="1">hello</p>`,
      schema,
    });
    const expected = doc(p('hello'));
    expect(node).toEqualProsemirrorNode(expected);
  });

  it('it produces valid html', () =&gt; {
    ({ schema } = createBaseTestManager([{ extension: new ParagraphExtension(), priority: 1 }]));
github ifiokjr / remirror / @remirror / core-extensions / src / marks / __tests__ / link-extension.spec.ts View on Github external
beforeEach(() => {
    ({ schema } = createBaseTestManager([{ extension: new LinkExtension(), priority: 1 }]));
    ({ a, doc, p } = pmBuild(schema, {
      a: { markType: 'link', href },
    }));
  });