2022-05-24 17:02:11 -05:00
|
|
|
import { renderMarkdown } from '../dist/index.js';
|
|
|
|
import chai from 'chai';
|
|
|
|
|
|
|
|
describe('components', () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const renderAstroMd = (text) => renderMarkdown(text, { isAstroFlavoredMd: true });
|
|
|
|
|
2022-05-24 17:02:11 -05:00
|
|
|
it('should be able to serialize string', async () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const { code } = await renderAstroMd(`<Component str="cool!" />`);
|
2022-05-24 17:02:11 -05:00
|
|
|
|
|
|
|
chai.expect(code).to.equal(`<Component str="cool!" />`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to serialize boolean attribute', async () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const { code } = await renderAstroMd(`<Component bool={true} />`);
|
2022-05-24 17:02:11 -05:00
|
|
|
|
|
|
|
chai.expect(code).to.equal(`<Component bool={true} />`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to serialize array', async () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const { code } = await renderAstroMd(`<Component prop={["a", "b", "c"]} />`);
|
2022-05-24 17:02:11 -05:00
|
|
|
|
|
|
|
chai.expect(code).to.equal(`<Component prop={["a", "b", "c"]} />`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to serialize object', async () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const { code } = await renderAstroMd(`<Component prop={{ a: 0, b: 1, c: 2 }} />`);
|
2022-05-24 17:02:11 -05:00
|
|
|
|
|
|
|
chai.expect(code).to.equal(`<Component prop={{ a: 0, b: 1, c: 2 }} />`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to serialize empty attribute', async () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const { code } = await renderAstroMd(`<Component empty />`);
|
2022-05-24 17:02:11 -05:00
|
|
|
|
|
|
|
chai.expect(code).to.equal(`<Component empty />`);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Notable omission: shorthand attribute
|
|
|
|
|
|
|
|
it('should be able to serialize spread attribute', async () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const { code } = await renderAstroMd(`<Component {...spread} />`);
|
2022-05-24 17:02:11 -05:00
|
|
|
|
|
|
|
chai.expect(code).to.equal(`<Component {...spread} />`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow client:* directives', async () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const { code } = await renderAstroMd(`<Component client:load />`);
|
2022-05-24 17:02:11 -05:00
|
|
|
|
|
|
|
chai.expect(code).to.equal(`<Component client:load />`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should normalize children', async () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const { code } = await renderAstroMd(`<Component bool={true}>Hello world!</Component>`);
|
2022-05-24 17:02:11 -05:00
|
|
|
|
2022-06-17 11:52:37 -05:00
|
|
|
chai.expect(code).to.equal(`<Component bool={true}>Hello world!</Component>`);
|
2022-05-31 12:16:43 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to nest components', async () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const { code } = await renderAstroMd(
|
2022-05-31 12:16:43 -05:00
|
|
|
`<Component bool={true}><Component>Hello world!</Component></Component>`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
|
|
|
chai
|
|
|
|
.expect(code)
|
2022-06-17 11:52:37 -05:00
|
|
|
.to.equal(`<Component bool={true}><Component>Hello world!</Component></Component>`);
|
2022-05-24 17:02:11 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow markdown without many spaces', async () => {
|
2022-07-22 17:45:16 -05:00
|
|
|
const { code } = await renderAstroMd(
|
2022-05-24 17:03:29 -05:00
|
|
|
`<Component>
|
2022-05-24 17:02:11 -05:00
|
|
|
# Hello world!
|
2022-05-24 17:03:29 -05:00
|
|
|
</Component>`,
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
2022-06-17 11:52:37 -05:00
|
|
|
chai.expect(code).to.equal(`<Component><h1 id="hello-world">Hello world!</h1></Component>`);
|
2022-05-24 17:02:11 -05:00
|
|
|
});
|
|
|
|
});
|