diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/elements/Dom.js | 24 | ||||
-rw-r--r-- | spec/spec/elements/Element.js | 4 | ||||
-rw-r--r-- | spec/spec/elements/Text.js | 10 |
3 files changed, 31 insertions, 7 deletions
diff --git a/spec/spec/elements/Dom.js b/spec/spec/elements/Dom.js index 3325d93..11ce9e0 100644 --- a/spec/spec/elements/Dom.js +++ b/spec/spec/elements/Dom.js @@ -10,7 +10,8 @@ import { Fragment, Circle, Tspan, - create + create, + Text } from '../../../src/main.js' import { getWindow } from '../../../src/utils/window.js' import { svg, html } from '../../../src/modules/core/namespaces.js' @@ -657,9 +658,24 @@ describe('Dom.js', function () { }) }) - // describe('writeDataToDom()', () => { - // // not really testable - // }) + describe('writeDataToDom()', () => { + it('writes the data to the dom', () => { + const node = new Rect() + node.setData({ foo: 'bar' }) + node.writeDataToDom() + expect(node.node.getAttribute('svgjs:data')).toBe('{"foo":"bar"}') + }) + + it('filters out default data', () => { + const node1 = new Text() + const node2 = new Text() + node2.dom.foo = 'bar' + node1.writeDataToDom() + node2.writeDataToDom() + expect(node1.node.getAttribute('svgjs:data')).toBe(null) + expect(node2.node.getAttribute('svgjs:data')).toBe('{"foo":"bar"}') + }) + }) describe('xml()', () => { describe('as setter', () => { diff --git a/spec/spec/elements/Element.js b/spec/spec/elements/Element.js index 53c5028..c89f7aa 100644 --- a/spec/spec/elements/Element.js +++ b/spec/spec/elements/Element.js @@ -165,7 +165,7 @@ describe('Element.js', function () { describe('parents()', () => { it('returns array of parents until the passed element or root svg', () => { const canvas = SVG().addTo(container) - const groupA = canvas.group().addClass('test') + const _groupA = canvas.group().addClass('test') const group1 = canvas.group().addClass('test') const group2 = group1.group() const group3 = group2.group() @@ -179,7 +179,7 @@ describe('Element.js', function () { it('returns array of parents until the closest matching parent', () => { const canvas = SVG().addTo(container) - const groupA = canvas.group().addClass('test') + const _groupA = canvas.group().addClass('test') const group1 = canvas.group().addClass('test') const group2 = group1.group().addClass('test').addClass('foo') const group3 = group2.group().addClass('foo') diff --git a/spec/spec/elements/Text.js b/spec/spec/elements/Text.js index f088618..28802a2 100644 --- a/spec/spec/elements/Text.js +++ b/spec/spec/elements/Text.js @@ -6,7 +6,8 @@ import { SVG, G, Path, - TextPath + TextPath, + Svg } from '../../../src/main.js' const { any } = jasmine @@ -20,6 +21,13 @@ describe('Text.js', () => { it('sets passed attributes on the element', () => { expect(new Text({ id: 'foo' }).id()).toBe('foo') }) + + it('recovers leading data from dom', () => { + const svg = new Svg().namespace() + svg.text('').leading(3) + const newSvg = SVG(svg.svg()) + expect(newSvg.findOne('text').leading().valueOf()).toBe(3) + }) }) describe('text()', () => { |