Skip to content

Commit 5634a89

Browse files
fix(markdownrender): add async wait for markdown evaluation in tests
MarkdownRender component evaluates markdown content asynchronously in componentDidMount. The tests were asserting immediately after mount without waiting for the async evaluation to complete, causing all 4 table-related tests to fail. Added sleep(100) and render.update() after mount to ensure the async markdown parsing completes before assertions. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3ff77ee commit 5634a89

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/semi-ui/markdownRender/__test__/markdown.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import MarkdownRender from '../index'
22
import React from 'react';
33
import { mount } from 'enzyme';
44
import { BASE_CLASS_PREFIX } from '@douyinfe/semi-foundation/base/constants';
5+
import { sleep } from '../../_test_/utils';
56

67

78
describe(`MarkdownRender`, () => {
@@ -17,6 +18,10 @@ describe(`MarkdownRender`, () => {
1718
<MarkdownRender raw={content} />
1819
);
1920

21+
// wait for async markdown evaluation to complete
22+
await sleep(100);
23+
render.update();
24+
2025
// check if has table container
2126
expect(render.exists(`.${BASE_CLASS_PREFIX}-table-container`)).toEqual(true);
2227
// check if has table head & body
@@ -36,6 +41,10 @@ describe(`MarkdownRender`, () => {
3641
<MarkdownRender raw={content} />
3742
);
3843

44+
// wait for async markdown evaluation to complete
45+
await sleep(100);
46+
render.update();
47+
3948
// check if has table container
4049
expect(render.exists(`.${BASE_CLASS_PREFIX}-table-container`)).toEqual(true);
4150
// check if has table head & body
@@ -55,6 +64,10 @@ describe(`MarkdownRender`, () => {
5564
<MarkdownRender raw={content} />
5665
);
5766

67+
// wait for async markdown evaluation to complete
68+
await sleep(100);
69+
render.update();
70+
5871
// check if has table container
5972
expect(render.exists(`.${BASE_CLASS_PREFIX}-table-container`)).toEqual(true);
6073
// check if has table head & body
@@ -84,6 +97,10 @@ describe(`MarkdownRender`, () => {
8497
<MarkdownRender raw={content} format="mdx"/>
8598
);
8699

100+
// wait for async markdown evaluation to complete
101+
await sleep(100);
102+
render.update();
103+
87104
// check if has table container
88105
expect(render.exists(`.${BASE_CLASS_PREFIX}-table-container`)).toEqual(true);
89106
// check if has table head & body

0 commit comments

Comments
 (0)