smartmarkdown/test/test.both.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-01-19 20:09:27 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
2022-05-19 07:36:59 +00:00
import * as smartmarkdown from '../ts/index.js';
2018-09-22 19:58:33 +00:00
let smartMarkdownInstance: smartmarkdown.SmartMarkdown;
tap.test('should create a valid instance of SmartMarkdown', async () => {
smartMarkdownInstance = new smartmarkdown.SmartMarkdown();
2022-05-19 07:36:59 +00:00
expect(smartMarkdownInstance).toBeInstanceOf(smartmarkdown.SmartMarkdown);
});
tap.test('should convert a markdown string to html', async () => {
const markdownString = '# Hi!';
2022-05-20 14:03:35 +00:00
const mdParsedResult = await smartMarkdownInstance.getMdParsedResultFromMarkdown(markdownString);
const htmlString = mdParsedResult.html;
2022-05-19 07:36:59 +00:00
expect(htmlString).toEqual('<h1>Hi!</h1>\n');
});
2022-05-20 14:03:35 +00:00
tap.test('should get frontmatter', async () => {
const markdownString = `---
hello: yes
---
# hello there
`;
const mdParsedResult = await smartMarkdownInstance.getMdParsedResultFromMarkdown(markdownString);
expect(mdParsedResult.frontmatterData.hello).toEqual('yes');
});
tap.test('should convert a html string to markdown', async () => {
const htmlString = '<h1 id="hi">Hi!</h1>\n<h2>This is it!</h2>';
const markdownString = smartMarkdownInstance.htmlToMarkdown(htmlString);
console.log(markdownString);
2018-09-22 19:58:33 +00:00
});
tap.start();