mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 07:49:43 +02:00
test: Fix parse tests
This commit is contained in:
@@ -35,7 +35,7 @@ vi.mock('./diagrams/sequence/sequenceRenderer.js');
|
||||
|
||||
import assignWithDepth from './assignWithDepth.js';
|
||||
import type { MermaidConfig } from './config.type.js';
|
||||
import mermaid from './mermaid.js';
|
||||
import mermaid, { type ParseResult } from './mermaid.js';
|
||||
import mermaidAPI, {
|
||||
appendDivSvgG,
|
||||
cleanUpSvgCode,
|
||||
@@ -695,23 +695,29 @@ describe('mermaidAPI', () => {
|
||||
).resolves.toBe(false);
|
||||
});
|
||||
it('resolves for valid definition', async () => {
|
||||
await expect(mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).resolves
|
||||
.toMatchInlineSnapshot(`
|
||||
await expect(
|
||||
mermaidAPI
|
||||
.parse('graph TD;A--x|text including URL space|B;')
|
||||
.then((p) => ({ config: p.config }))
|
||||
).resolves.toMatchInlineSnapshot(`
|
||||
{
|
||||
"config": {},
|
||||
"diagramType": "flowchart-v2",
|
||||
}
|
||||
`);
|
||||
});
|
||||
it('returns config when defined in frontmatter', async () => {
|
||||
await expect(
|
||||
mermaidAPI.parse(`---
|
||||
mermaidAPI
|
||||
.parse(
|
||||
`---
|
||||
config:
|
||||
theme: base
|
||||
flowchart:
|
||||
htmlLabels: true
|
||||
---
|
||||
graph TD;A--x|text including URL space|B;`)
|
||||
graph TD;A--x|text including URL space|B;`
|
||||
)
|
||||
.then((p) => ({ config: p.config }))
|
||||
).resolves.toMatchInlineSnapshot(`
|
||||
{
|
||||
"config": {
|
||||
@@ -720,35 +726,41 @@ graph TD;A--x|text including URL space|B;`)
|
||||
},
|
||||
"theme": "base",
|
||||
},
|
||||
"diagramType": "flowchart-v2",
|
||||
}
|
||||
`);
|
||||
`);
|
||||
});
|
||||
|
||||
it('returns config when defined in directive', async () => {
|
||||
await expect(
|
||||
mermaidAPI.parse(`%%{init: { 'theme': 'base' } }%%
|
||||
graph TD;A--x|text including URL space|B;`)
|
||||
mermaidAPI
|
||||
.parse(
|
||||
`%%{init: { 'theme': 'base' } }%%
|
||||
graph TD;A--x|text including URL space|B;`
|
||||
)
|
||||
.then((p) => ({ config: p.config }))
|
||||
).resolves.toMatchInlineSnapshot(`
|
||||
{
|
||||
"config": {
|
||||
"theme": "base",
|
||||
},
|
||||
"diagramType": "flowchart-v2",
|
||||
}
|
||||
`);
|
||||
`);
|
||||
});
|
||||
|
||||
it('returns merged config when defined in frontmatter and directive', async () => {
|
||||
await expect(
|
||||
mermaidAPI.parse(`---
|
||||
mermaidAPI
|
||||
.parse(
|
||||
`---
|
||||
config:
|
||||
theme: forest
|
||||
flowchart:
|
||||
htmlLabels: true
|
||||
---
|
||||
%%{init: { 'theme': 'base' } }%%
|
||||
graph TD;A--x|text including URL space|B;`)
|
||||
graph TD;A--x|text including URL space|B;`
|
||||
)
|
||||
.then((p) => ({ config: p.config }))
|
||||
).resolves.toMatchInlineSnapshot(`
|
||||
{
|
||||
"config": {
|
||||
@@ -757,17 +769,17 @@ graph TD;A--x|text including URL space|B;`)
|
||||
},
|
||||
"theme": "base",
|
||||
},
|
||||
"diagramType": "flowchart-v2",
|
||||
}
|
||||
`);
|
||||
`);
|
||||
});
|
||||
it('returns true for valid definition with silent option', async () => {
|
||||
await expect(
|
||||
mermaidAPI.parse('graph TD;A--x|text including URL space|B;', { suppressErrors: true })
|
||||
mermaidAPI
|
||||
.parse('graph TD;A--x|text including URL space|B;', { suppressErrors: true })
|
||||
.then((p) => ({ config: (p as ParseResult).config }))
|
||||
).resolves.toMatchInlineSnapshot(`
|
||||
{
|
||||
"config": {},
|
||||
"diagramType": "flowchart-v2",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
Reference in New Issue
Block a user