Skip to content

Commit 0132afc

Browse files
Nagi-ovoclaude
andcommitted
test(user-latex): deflake mocked katex import race
A single setTimeout(0) flush loses to the mocked dynamic import under full-suite load, failing the assertion early and leaking the late continuation into the following test. Poll with vi.waitFor instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 6e3475a commit 0132afc

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/pages/content/userLatex/__tests__/userLatexRender.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ describe('userLatex dynamic KaTeX rendering', () => {
3333
it('lazily loads KaTeX and renders math when a user message contains LaTeX', async () => {
3434
const el = makeUserMessage('Euler: $e^{i\\pi}+1=0$ done');
3535
startUserLatex();
36-
await flush();
3736

38-
expect(renderToString).toHaveBeenCalled();
37+
// The mocked dynamic import('katex') can span several macrotasks under
38+
// full-suite load, so poll instead of a single setTimeout(0) flush —
39+
// otherwise the late continuation also leaks into the next test.
40+
await vi.waitFor(() => expect(renderToString).toHaveBeenCalled());
41+
3942
expect(el.dataset.userLatexProcessed).toBe('1');
4043
expect(el.querySelector('.katex-rendered')).not.toBeNull();
4144
});

0 commit comments

Comments
 (0)