mermaid/src/mermaidAPI.spec.js

46 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-04-11 22:57:57 +08:00
/* eslint-env jasmine */
2017-09-10 10:45:38 +08:00
import mermaidAPI from './mermaidAPI'
2017-04-11 22:14:25 +08:00
describe('when using mermaidAPI and ', function () {
describe('doing initialize ', function () {
beforeEach(function () {
document.body.innerHTML = ''
})
2017-04-11 22:14:25 +08:00
it('should copy a literal into the configuration', function () {
2017-09-14 19:32:35 +08:00
const orgConfig = mermaidAPI.getConfig()
2017-04-11 22:14:25 +08:00
expect(orgConfig.testLiteral).toBe(undefined)
2017-09-10 10:45:38 +08:00
mermaidAPI.initialize({ 'testLiteral': true })
2017-09-14 19:32:35 +08:00
const config = mermaidAPI.getConfig()
2017-04-11 22:14:25 +08:00
expect(config.testLiteral).toBe(true)
})
it('should copy a an object into the configuration', function () {
2017-09-14 19:32:35 +08:00
const orgConfig = mermaidAPI.getConfig()
2017-04-11 22:14:25 +08:00
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
}
2017-09-10 10:45:38 +08:00
mermaidAPI.initialize({ 'testObject': object })
mermaidAPI.initialize({ 'testObject': { 'test3': true } })
2017-09-14 19:32:35 +08:00
const config = mermaidAPI.getConfig()
2017-04-11 22:14:25 +08: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 () {
2017-09-10 10:45:38 +08:00
expect(() => mermaidAPI.parse('this is not a mermaid diagram definition')).toThrow()
2017-04-11 22:14:25 +08:00
})
it('it should not throw for a valid definiton', function () {
2017-09-10 10:45:38 +08:00
expect(() => mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).not.toThrow()
2017-04-11 22:14:25 +08:00
})
})
})