summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-03-01 12:42:16 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-03-01 12:42:16 +0100
commit75c3893a7c7af76f9bb1fe9be72e03b99d17a1e0 (patch)
tree16cec0ea31f80b2e48517e787097ab1d9d799ce7 /spec
parent981c1fb154e3999f91dd9c1eff97726d689240ff (diff)
downloadsvg.js-75c3893a7c7af76f9bb1fe9be72e03b99d17a1e0.tar.gz
svg.js-75c3893a7c7af76f9bb1fe9be72e03b99d17a1e0.zip
fixed all that errors which come along when removing an object. Fixed tests, too and added isRoot test
Diffstat (limited to 'spec')
-rw-r--r--spec/SpecRunner.html1
-rw-r--r--spec/spec/doc.js21
-rw-r--r--spec/spec/element.js3
-rw-r--r--spec/spec/nested.js13
-rw-r--r--spec/spec/svg.js4
5 files changed, 23 insertions, 19 deletions
diff --git a/spec/SpecRunner.html b/spec/SpecRunner.html
index 7461bdd..bd47626 100644
--- a/spec/SpecRunner.html
+++ b/spec/SpecRunner.html
@@ -78,7 +78,6 @@
<script src="spec/mask.js"></script>
<script src="spec/matrix.js"></script>
<script src="spec/memory.js"></script>
- <script src="spec/nested.js"></script>
<script src="spec/number.js"></script>
<script src="spec/path.js"></script>
<script src="spec/pattern.js"></script>
diff --git a/spec/spec/doc.js b/spec/spec/doc.js
index 1e1c54c..5accd5b 100644
--- a/spec/spec/doc.js
+++ b/spec/spec/doc.js
@@ -16,11 +16,11 @@ describe('Doc', function() {
expect(draw instanceof SVG.Doc).toBe(true)
})
- it('returns itself as Doc', function() {
+ it('returns itself as Doc when root', function() {
expect(draw.doc()).toBe(draw)
})
- it('has a defs element', function() {
+ it('has a defs element when root', function() {
expect(draw.defs() instanceof SVG.Defs).toBe(true)
})
@@ -33,6 +33,23 @@ describe('Doc', function() {
})
})
+ describe('isRoot()', function() {
+ it('returns true when the doc is not attached to dom', function() {
+ expect(SVG().isRoot()).toBe(true)
+ })
+ it('returns true when its outer element is not an svg element', function () {
+ expect(SVG().addTo(document.createElement('div')).isRoot()).toBe(true)
+ })
+ it('returns true when its the root element of the dom', function () {
+ if(parserInDoc) {
+ expect(draw.isRoot()).toBe(true)
+ }
+ })
+ it('returns false when parent is svg element', function () {
+ expect(SVG().addTo(SVG()).isRoot()).toBe(false)
+ })
+ })
+
describe('remove()', function() {
it('removes the doc from the dom only if doc is not root element', function() {
var cnt = window.document.querySelectorAll('svg').length
diff --git a/spec/spec/element.js b/spec/spec/element.js
index a5b26a1..53ed84f 100644
--- a/spec/spec/element.js
+++ b/spec/spec/element.js
@@ -476,11 +476,12 @@ describe('Element', function() {
it('ungroups everything to the doc root when called on SVG.Doc / does not ungroup defs/parser', function() {
draw.flatten()
+
expect(rect1.parent()).toBe(draw)
expect(rect2.parent()).toBe(draw)
expect(g1.node.parentNode).toBeFalsy()
- expect(g1.node.parentNode).toBeFalsy()
+ expect(g2.node.parentNode).toBeFalsy()
expect(nested.node.parentNode).toBeFalsy()
expect(rect1.transform()).toEqual(jasmine.objectContaining({
diff --git a/spec/spec/nested.js b/spec/spec/nested.js
deleted file mode 100644
index 3113880..0000000
--- a/spec/spec/nested.js
+++ /dev/null
@@ -1,13 +0,0 @@
-describe('Nested', function() {
-
- afterEach(function() {
- draw.clear()
- })
-
- describe('()', function() {
- it('creates a nested svg of type SVG.Nested', function() {
- expect(draw.nested() instanceof SVG.Nested).toBeTruthy()
- })
- })
-
-})
diff --git a/spec/spec/svg.js b/spec/spec/svg.js
index 2485a32..ea51703 100644
--- a/spec/spec/svg.js
+++ b/spec/spec/svg.js
@@ -52,10 +52,10 @@ describe('SVG', function() {
expect(SVG(rect).node).toBe(rect)
})
- it('creates an instanceof SVG.Nested when importing a whole svg', function() {
+ it('creates an instanceof SVG.Doc when importing a whole svg', function() {
var doc = SVG('<svg width="200"><rect></rect></svg>')
- expect(doc instanceof SVG.Nested).toBe(true)
+ expect(doc instanceof SVG.Doc).toBe(true)
expect(doc.node.nodeName).toBe('svg')
expect(doc.width()).toBe(200)
expect(doc.get(0).node.nodeName).toBe('rect')