aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/elements/Dom.js22
-rw-r--r--spec/spec/elements/Element.js25
-rw-r--r--spec/spec/elements/Svg.js8
3 files changed, 22 insertions, 33 deletions
diff --git a/spec/spec/elements/Dom.js b/spec/spec/elements/Dom.js
index 11ce9e0..00879d0 100644
--- a/spec/spec/elements/Dom.js
+++ b/spec/spec/elements/Dom.js
@@ -10,8 +10,7 @@ import {
Fragment,
Circle,
Tspan,
- create,
- Text
+ create
} from '../../../src/main.js'
import { getWindow } from '../../../src/utils/window.js'
import { svg, html } from '../../../src/modules/core/namespaces.js'
@@ -658,25 +657,6 @@ describe('Dom.js', function () {
})
})
- 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', () => {
it('returns itself', () => {
diff --git a/spec/spec/elements/Element.js b/spec/spec/elements/Element.js
index c89f7aa..93cee3b 100644
--- a/spec/spec/elements/Element.js
+++ b/spec/spec/elements/Element.js
@@ -1,6 +1,6 @@
/* globals describe, expect, it, beforeEach, spyOn, jasmine, container */
-import { Element, create, Rect, G, SVG } from '../../../src/main.js'
+import { Element, create, Rect, G, SVG, Text } from '../../../src/main.js'
const { any, objectContaining } = jasmine
describe('Element.js', function () {
@@ -34,9 +34,14 @@ describe('Element.js', function () {
})
it('falls back to empty object when attribute is null', () => {
- element.node.setAttribute('svgjs:data', 'null')
+ element.node.setAttribute('data-svg', 'null')
expect(new Element(element.node).dom).toEqual({})
})
+
+ it('uses old svgjs:data attribute if present', () => {
+ element.node.setAttribute('svgjs:data', '{"foo":"bar"}')
+ expect(new Element(element.node).dom).toEqual({ foo: 'bar' })
+ })
})
describe('center()', () => {
@@ -265,15 +270,15 @@ describe('Element.js', function () {
describe('writeDataToDom()', () => {
it('removes previously set data', () => {
- element.node.setAttribute('svgjs:data', JSON.stringify({ foo: 'bar' }))
+ element.node.setAttribute('data-svgjs', JSON.stringify({ foo: 'bar' }))
element.writeDataToDom()
- expect(element.node.getAttribute('svgjs:data')).toBe(null)
+ expect(element.node.getAttribute('data-svgjs')).toBe(null)
})
it('writes data from the dom property into the dom', () => {
element.dom = { foo: 'bar' }
element.writeDataToDom()
- expect(element.node.getAttribute('svgjs:data')).toBe(
+ expect(element.node.getAttribute('data-svgjs')).toBe(
JSON.stringify({ foo: 'bar' })
)
})
@@ -285,6 +290,16 @@ describe('Element.js', function () {
g.writeDataToDom()
expect(spy).toHaveBeenCalled()
})
+
+ 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('data-svgjs')).toBe(null)
+ expect(node2.node.getAttribute('data-svgjs')).toBe('{"foo":"bar"}')
+ })
})
describe('x()', () => {
diff --git a/spec/spec/elements/Svg.js b/spec/spec/elements/Svg.js
index 6da7729..ebe3b52 100644
--- a/spec/spec/elements/Svg.js
+++ b/spec/spec/elements/Svg.js
@@ -1,11 +1,7 @@
/* globals describe, expect, it, jasmine, container */
import { Svg, SVG, Defs } from '../../../src/main.js'
-import {
- svg as ns,
- xlink,
- svgjs
-} from '../../../src/modules/core/namespaces.js'
+import { svg as ns, xlink } from '../../../src/modules/core/namespaces.js'
import { getWindow } from '../../../src/utils/window.js'
const { any } = jasmine
@@ -26,7 +22,6 @@ describe('Svg.js', () => {
expect(svg.attr('xmlns')).toBe(ns)
expect(svg.attr('version')).toBe(1.1)
expect(svg.attr('xmlns:xlink')).toBe(xlink)
- expect(svg.attr('xmlns:svgjs')).toBe(svgjs)
})
})
@@ -71,7 +66,6 @@ describe('Svg.js', () => {
expect(svg.attr('xmlns')).toBe(ns)
expect(svg.attr('version')).toBe(1.1)
expect(svg.attr('xmlns:xlink')).toBe(xlink)
- expect(svg.attr('xmlns:svgjs')).toBe(svgjs)
})
})