summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/test/expressions.test.js
blob: c3c341acd1f5a328e4b7669a575ada45d94a87ec (plain) (blame)
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
47
48
49
50
51
import { renderMarkdown } from '../dist/index.js';
import chai from 'chai';

describe('expressions', () => {
	it('should be able to serialize bare expession', async () => {
		const { code } = await renderMarkdown(`{a}`, {});

		chai.expect(code).to.equal(`{a}`);
	});

	it('should be able to serialize expression inside component', async () => {
		const { code } = await renderMarkdown(`<Component>{a}</Component>`, {});

		chai.expect(code).to.equal(`\n<Component>{a}</Component>\n`);
	});

	it('should be able to serialize expression inside markdown', async () => {
		const { code } = await renderMarkdown(`# {frontmatter.title}`, {});

		chai
			.expect(code)
			.to.equal(`<h1 id={$$slug(\`\${frontmatter.title}\`)}>{frontmatter.title}</h1>`);
	});

	it('should be able to serialize complex expression inside markdown', async () => {
		const { code } = await renderMarkdown(`# Hello {frontmatter.name}`, {});

		chai
			.expect(code)
			.to.equal(`<h1 id={$$slug(\`Hello \${frontmatter.name}\`)}>Hello {frontmatter.name}</h1>`);
	});

	it('should be able to serialize complex expression with markup inside markdown', async () => {
		const { code } = await renderMarkdown(`# Hello <span>{frontmatter.name}</span>`, {});

		chai
			.expect(code)
			.to.equal(
				`<h1 id={$$slug(\`Hello \${frontmatter.name}\`)}>Hello <span>{frontmatter.name}</span></h1>`
			);
	});

	it('should be able to serialize function expression', async () => {
		const { code } = await renderMarkdown(
			`{frontmatter.list.map(item => <p id={item}>{item}</p>)}`,
			{}
		);

		chai.expect(code).to.equal(`{frontmatter.list.map(item => <p id={item}>{item}</p>)}`);
	});
});