summaryrefslogtreecommitdiff
path: root/spec/frontend/lib/gfm/index_spec.js
blob: 5c72b5a51a7cc14f3f8d240eef103dd4343b8b32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { render } from '~/lib/gfm';

describe('gfm', () => {
  describe('render', () => {
    it('processes Commonmark and provides an ast to the renderer function', async () => {
      let result;

      await render({
        markdown: 'This is text',
        renderer: (tree) => {
          result = tree;
        },
      });

      expect(result.type).toBe('root');
    });

    it('transforms raw HTML into individual nodes in the AST', async () => {
      let result;

      await render({
        markdown: '<strong>This is bold text</strong>',
        renderer: (tree) => {
          result = tree;
        },
      });

      expect(result.children[0].children[0]).toMatchObject({
        type: 'element',
        tagName: 'strong',
        properties: {},
      });
    });

    it('returns the result of executing the renderer function', async () => {
      const result = await render({
        markdown: '<strong>This is bold text</strong>',
        renderer: () => {
          return 'rendered tree';
        },
      });

      expect(result).toBe('rendered tree');
    });
  });
});