2022-05-24 17:02:11 -05:00
|
|
|
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>`, {});
|
|
|
|
|
2022-05-31 12:16:43 -05:00
|
|
|
chai.expect(code).to.equal(`\n<Component>{a}</Component>\n`);
|
2022-05-24 17:02:11 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to serialize expression inside markdown', async () => {
|
|
|
|
const { code } = await renderMarkdown(`# {frontmatter.title}`, {});
|
|
|
|
|
2022-05-24 17:03:29 -05:00
|
|
|
chai
|
|
|
|
.expect(code)
|
|
|
|
.to.equal(`<h1 id={$$slug(\`\${frontmatter.title}\`)}>{frontmatter.title}</h1>`);
|
2022-05-24 17:02:11 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to serialize complex expression inside markdown', async () => {
|
|
|
|
const { code } = await renderMarkdown(`# Hello {frontmatter.name}`, {});
|
|
|
|
|
2022-05-24 17:03:29 -05:00
|
|
|
chai
|
|
|
|
.expect(code)
|
|
|
|
.to.equal(`<h1 id={$$slug(\`Hello \${frontmatter.name}\`)}>Hello {frontmatter.name}</h1>`);
|
2022-05-24 17:02:11 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to serialize complex expression with markup inside markdown', async () => {
|
|
|
|
const { code } = await renderMarkdown(`# Hello <span>{frontmatter.name}</span>`, {});
|
|
|
|
|
2022-05-24 17:03:29 -05:00
|
|
|
chai
|
|
|
|
.expect(code)
|
|
|
|
.to.equal(
|
|
|
|
`<h1 id={$$slug(\`Hello \${frontmatter.name}\`)}>Hello <span>{frontmatter.name}</span></h1>`
|
|
|
|
);
|
2022-05-24 17:02:11 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to serialize function expression', async () => {
|
2022-05-24 17:03:29 -05:00
|
|
|
const { code } = await renderMarkdown(
|
|
|
|
`{frontmatter.list.map(item => <p id={item}>{item}</p>)}`,
|
|
|
|
{}
|
|
|
|
);
|
2022-05-24 17:02:11 -05:00
|
|
|
|
|
|
|
chai.expect(code).to.equal(`{frontmatter.list.map(item => <p id={item}>{item}</p>)}`);
|
2022-05-24 17:03:29 -05:00
|
|
|
});
|
2022-05-24 17:02:11 -05:00
|
|
|
});
|