mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 16:29:40 +02:00
add more test for mermaidAPI.parse() to ensure it matches documented behavior
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import mermaid from './mermaid';
|
||||||
import mermaidAPI from './mermaidAPI';
|
import mermaidAPI from './mermaidAPI';
|
||||||
import { assignWithDepth } from './utils';
|
import { assignWithDepth } from './utils';
|
||||||
|
|
||||||
@@ -119,12 +120,28 @@ describe('when using mermaidAPI and ', function () {
|
|||||||
expect(mermaidAPI.getConfig().dompurifyConfig.ADD_ATTR).toEqual(['onclick']);
|
expect(mermaidAPI.getConfig().dompurifyConfig.ADD_ATTR).toEqual(['onclick']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('checking validity of input ', function () {
|
describe('test mermaidApi.parse() for checking validity of input ', function () {
|
||||||
it('it should throw for an invalid definiton', function () {
|
mermaid.parseError = undefined; // ensure it parseError undefined
|
||||||
|
it('it should throw for an invalid definiton (with no mermaid.parseError() defined)', function () {
|
||||||
|
expect(mermaid.parseError).toEqual(undefined);
|
||||||
expect(() => mermaidAPI.parse('this is not a mermaid diagram definition')).toThrow();
|
expect(() => mermaidAPI.parse('this is not a mermaid diagram definition')).toThrow();
|
||||||
});
|
});
|
||||||
it('it should not throw for a valid definiton', function () {
|
it('it should not throw for a valid definiton', function () {
|
||||||
expect(() => mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).not.toThrow();
|
expect(() => mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).not.toThrow();
|
||||||
});
|
});
|
||||||
|
it('it should return false for invalid definiton WITH a parseError() callback defined', function () {
|
||||||
|
var parseErrorWasCalled = false;
|
||||||
|
// also test setParseErrorHandler() call working to set mermaid.parseError
|
||||||
|
mermaid.setParseErrorHandler(function (error, hash) {
|
||||||
|
// got here.
|
||||||
|
parseErrorWasCalled = true;
|
||||||
|
});
|
||||||
|
expect(mermaid.parseError).not.toEqual(undefined);
|
||||||
|
expect(mermaidAPI.parse('this is not a mermaid diagram definition')).toEqual(false);
|
||||||
|
expect(parseErrorWasCalled).toEqual(true);
|
||||||
|
});
|
||||||
|
it('it should return true for valid definiton', function () {
|
||||||
|
expect(mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).toEqual(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user