mermaid/src/mermaidAPI.spec.js

51 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-04-11 22:57:57 +08:00
/* eslint-env jasmine */
2019-09-12 12:59:13 -07:00
import mermaidAPI from './mermaidAPI';
2019-09-12 12:59:13 -07:00
describe('when using mermaidAPI and ', function() {
describe('doing initialize ', function() {
beforeEach(function() {
document.body.innerHTML = '';
});
2019-09-12 12:59:13 -07:00
it('should copy a literal into the configuration', function() {
const orgConfig = mermaidAPI.getConfig();
expect(orgConfig.testLiteral).toBe(undefined);
2019-09-12 12:59:13 -07:00
mermaidAPI.initialize({ testLiteral: true });
const config = mermaidAPI.getConfig();
2019-09-12 12:59:13 -07:00
expect(config.testLiteral).toBe(true);
});
it('should copy a an object into the configuration', function() {
const orgConfig = mermaidAPI.getConfig();
expect(orgConfig.testObject).toBe(undefined);
2017-09-14 19:32:35 +08:00
const object = {
2017-04-11 22:14:25 +08:00
test1: 1,
test2: false
2019-09-12 12:59:13 -07:00
};
2019-09-12 12:59:13 -07:00
mermaidAPI.initialize({ testObject: object });
2020-06-15 01:11:56 +02:00
let config = mermaidAPI.getConfig();
console.log('1:', config);
expect(config.testObject.test1).toBe(1);
2019-09-12 12:59:13 -07:00
mermaidAPI.initialize({ testObject: { test3: true } });
2020-06-15 01:11:56 +02:00
config = mermaidAPI.getConfig();
console.log(config);
2019-09-12 12:59:13 -07:00
expect(config.testObject.test1).toBe(1);
expect(config.testObject.test2).toBe(false);
expect(config.testObject.test3).toBe(true);
});
});
describe('checking validity of input ', function() {
it('it should throw for an invalid definiton', function() {
expect(() => mermaidAPI.parse('this is not a mermaid diagram definition')).toThrow();
});
it('it should not throw for a valid definiton', function() {
expect(() => mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).not.toThrow();
});
});
});