tagHandler - Handle strong and em tags + test

This commit is contained in:
2019-12-21 13:44:10 +05:30
parent ef7af9797c
commit 19add2a956
2 changed files with 19 additions and 0 deletions
+12
View File
@@ -41,3 +41,15 @@ test('should render plain text with simple Class Component', () => {
test('should render plain H1 with text', () => {
expect((render(<h1>abcd</h1>) as string).trim()).toBe('# abcd');
});
test('should render plain strong with text', () => {
expect((render(<strong>abcd</strong>) as string).trim()).toBe('**abcd**');
});
test('should render plain em with text', () => {
expect((render(<em>abcd</em>) as string).trim()).toBe('_abcd_');
});
test('should render H1 with mixed strong and em text', () => {
expect((render(<h1>This is <strong>Hello</strong> <em>World</em></h1>) as string).trim()).toBe('# This is **Hello** _World_');
});
+7
View File
@@ -17,6 +17,13 @@ export default function handleTag(
newParentASTNode = childASTNode = heading(1);
break;
case 'strong':
newParentASTNode = childASTNode = strong();
break;
case 'em':
newParentASTNode = childASTNode = emphasis();
break;
default:
newParentASTNode = parentASTNode;
break;