Now with tests!
This commit is contained in:
parent
f47e09768e
commit
9ed72e9f45
3 changed files with 39 additions and 4 deletions
|
@ -61,7 +61,7 @@ Defs.prototype.remove = function (name) {
|
|||
Defs.prototype.render = function () {
|
||||
let svg = ''
|
||||
for (let key in this.list) {
|
||||
svg += ` ${key}="${this.list[key].join('')}"`
|
||||
svg += ` ${key}="${this.list[key]}"`
|
||||
}
|
||||
|
||||
return svg
|
||||
|
@ -75,7 +75,7 @@ Defs.prototype.render = function () {
|
|||
* @return {Defs} this - The Defs instance
|
||||
*/
|
||||
Defs.prototype.set = function (name, value) {
|
||||
this.list[name] = [value]
|
||||
this.list[name] = value
|
||||
|
||||
return this
|
||||
}
|
||||
|
@ -88,6 +88,6 @@ Defs.prototype.set = function (name, value) {
|
|||
* @return {Defs} this - The Defs instance
|
||||
*/
|
||||
Defs.prototype.setIfUnset = function (name, value) {
|
||||
if (typeof this.list[name] === 'undefined') this.list[name] = [value]
|
||||
if (typeof this.list[name] === 'undefined') this.list[name] = value
|
||||
return this
|
||||
}
|
||||
|
|
34
packages/core/tests/defs.test.mjs
Normal file
34
packages/core/tests/defs.test.mjs
Normal file
|
@ -0,0 +1,34 @@
|
|||
import chai from 'chai'
|
||||
import { Defs } from '../src/defs.mjs'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Defs', () => {
|
||||
let defs = new Defs()
|
||||
|
||||
it('Should set a def', () => {
|
||||
defs.set('test', 'passed')
|
||||
expect(defs.get('test')).to.equal('passed')
|
||||
})
|
||||
|
||||
it('Should remove a def', () => {
|
||||
defs.remove('test')
|
||||
expect(defs.get('test')).to.equal(false)
|
||||
})
|
||||
|
||||
it('Should only set an unset def', () => {
|
||||
defs.setIfUnset('test', 'passed')
|
||||
expect(defs.get('test')).to.equal('passed')
|
||||
defs.setIfUnset('test', 'failed')
|
||||
expect(defs.get('test')).to.equal('passed')
|
||||
})
|
||||
|
||||
it('Should return false when getting an unset def', () => {
|
||||
expect(defs.get('doNotTest')).to.equal(false)
|
||||
})
|
||||
|
||||
it('Should render defs correctly', () => {
|
||||
console.log(defs.render())
|
||||
expect(defs.render()).to.equal(' test="passed"')
|
||||
})
|
||||
})
|
|
@ -2,6 +2,7 @@ import chai from 'chai'
|
|||
import chaiString from 'chai-string'
|
||||
import { Svg } from '../src/svg.mjs'
|
||||
import { Design, Attributes } from '../src/index.mjs'
|
||||
import { Defs } from '../src/defs.mjs'
|
||||
import { version } from '../data.mjs'
|
||||
import render from './fixtures/render.mjs'
|
||||
|
||||
|
@ -42,7 +43,7 @@ describe('Svg', () => {
|
|||
expect(svg.freeId).to.equal(0)
|
||||
expect(svg.body).to.equal('')
|
||||
expect(svg.style).to.equal('')
|
||||
expect(svg.defs).to.equal('')
|
||||
expect(svg.defs instanceof Defs).to.equal(true)
|
||||
expect(svg.prefix).to.equal('<?xml version="1.0" encoding="UTF-8" standalone="no"?>')
|
||||
expect(svg.attributes.get('xmlns')).to.equal('http://www.w3.org/2000/svg')
|
||||
expect(svg.attributes.get('xmlns:svg')).to.equal('http://www.w3.org/2000/svg')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue