mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 07:19:41 +02:00
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
/**
|
|
* Mocks for `./mermaidAPI`.
|
|
*
|
|
* We can't easily use `vi.spyOn(mermaidAPI, "function")` since the object is frozen with `Object.freeze()`.
|
|
*/
|
|
import * as configApi from '../config';
|
|
import { vi } from 'vitest';
|
|
import { addDiagrams } from '../diagram-api/diagram-orchestration';
|
|
import Diagram, { type ParseErrorFunction } from '../Diagram';
|
|
|
|
// Normally, we could just do the following to get the original `parse()`
|
|
// implementation, however, requireActual returns a promise and it's not documented how to use withing mock file.
|
|
|
|
/**
|
|
* @param text
|
|
* @param parseError
|
|
*/
|
|
function parse(text: string, parseError?: ParseErrorFunction): boolean {
|
|
addDiagrams();
|
|
const diagram = new Diagram(text, parseError);
|
|
return diagram.parse(text, parseError);
|
|
}
|
|
|
|
// original version cannot be modified since it was frozen with `Object.freeze()`
|
|
export const mermaidAPI = {
|
|
render: vi.fn(),
|
|
parse,
|
|
parseDirective: vi.fn(),
|
|
initialize: vi.fn(),
|
|
getConfig: configApi.getConfig,
|
|
setConfig: configApi.setConfig,
|
|
getSiteConfig: configApi.getSiteConfig,
|
|
updateSiteConfig: configApi.updateSiteConfig,
|
|
reset: () => {
|
|
configApi.reset();
|
|
},
|
|
globalReset: () => {
|
|
configApi.reset(configApi.defaultConfig);
|
|
},
|
|
defaultConfig: configApi.defaultConfig,
|
|
};
|
|
|
|
export default mermaidAPI;
|