From 64081d9a1ba1bd17865f5c750f67b7e2b450fd87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Cunat?= Date: Mon, 26 Feb 2018 18:26:42 +0100 Subject: [PATCH 1/6] fix classes for svg element --- src/wrappers/wrapper.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wrappers/wrapper.js b/src/wrappers/wrapper.js index 309c6690f..fc34a5927 100644 --- a/src/wrappers/wrapper.js +++ b/src/wrappers/wrapper.js @@ -69,7 +69,12 @@ export default class Wrapper implements BaseWrapper { * Returns an Array containing all the classes on the element */ classes (): Array { - let classes = this.element.className ? this.element.className.split(' ') : [] + let classes = this.element.className; + if (classes instanceof SVGAnimatedString) { + classes = this.element.getAttribute('class') || []; + } else { + classes = this.element.className ? this.element.className.split(' ') : []; + } // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { const cssModuleIdentifiers = {} From c8bc75d040244594eb57d03a6eb2bb7918b9d37a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Cunat?= Date: Mon, 26 Feb 2018 18:40:59 +0100 Subject: [PATCH 2/6] fix eslint --- .eslintrc | 3 ++- src/wrappers/wrapper.js | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.eslintrc b/.eslintrc index 069c07d70..a2a1d6b81 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,7 +2,8 @@ "globals": { "wrapper": true, "expect": true, - "Element": true + "Element": true, + "SVGAnimatedString": true }, "root": true, "plugins": [ diff --git a/src/wrappers/wrapper.js b/src/wrappers/wrapper.js index fc34a5927..428fb8ed2 100644 --- a/src/wrappers/wrapper.js +++ b/src/wrappers/wrapper.js @@ -69,11 +69,11 @@ export default class Wrapper implements BaseWrapper { * Returns an Array containing all the classes on the element */ classes (): Array { - let classes = this.element.className; + let classes = this.element.className if (classes instanceof SVGAnimatedString) { - classes = this.element.getAttribute('class') || []; + classes = this.element.getAttribute('class') || [] } else { - classes = this.element.className ? this.element.className.split(' ') : []; + classes = this.element.className ? this.element.className.split(' ') : [] } // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { From 4995afd5de2b0196229428c7f8d8fb99a098d840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Cunat?= Date: Mon, 26 Feb 2018 18:57:09 +0100 Subject: [PATCH 3/6] simplify fix --- .eslintrc | 3 +-- src/wrappers/wrapper.js | 10 ++++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index a2a1d6b81..069c07d70 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,8 +2,7 @@ "globals": { "wrapper": true, "expect": true, - "Element": true, - "SVGAnimatedString": true + "Element": true }, "root": true, "plugins": [ diff --git a/src/wrappers/wrapper.js b/src/wrappers/wrapper.js index 428fb8ed2..8cfeac50b 100644 --- a/src/wrappers/wrapper.js +++ b/src/wrappers/wrapper.js @@ -69,12 +69,10 @@ export default class Wrapper implements BaseWrapper { * Returns an Array containing all the classes on the element */ classes (): Array { - let classes = this.element.className - if (classes instanceof SVGAnimatedString) { - classes = this.element.getAttribute('class') || [] - } else { - classes = this.element.className ? this.element.className.split(' ') : [] - } + // works for HTML Element and SVG Element + let className = this.element.getAttribute('class') + let classes = className ? className.split(' ') : [] + // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { const cssModuleIdentifiers = {} From 385f429fb20de86786b1f9ce93cb9928d757dd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Cunat?= Date: Mon, 26 Feb 2018 19:43:38 +0100 Subject: [PATCH 4/6] remove spaces --- src/wrappers/wrapper.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wrappers/wrapper.js b/src/wrappers/wrapper.js index 8cfeac50b..0a4d5d62b 100644 --- a/src/wrappers/wrapper.js +++ b/src/wrappers/wrapper.js @@ -70,9 +70,8 @@ export default class Wrapper implements BaseWrapper { */ classes (): Array { // works for HTML Element and SVG Element - let className = this.element.getAttribute('class') - let classes = className ? className.split(' ') : [] - + const className = this.element.getAttribute('class') + let classes = className ? className.split(' ') : [] // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { const cssModuleIdentifiers = {} From 9730f0da950db8cb1a17a7dbef7634690964f950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Cunat?= Date: Mon, 26 Feb 2018 19:46:48 +0100 Subject: [PATCH 5/6] Update wrapper.js --- src/wrappers/wrapper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrappers/wrapper.js b/src/wrappers/wrapper.js index 0a4d5d62b..8b8ca3780 100644 --- a/src/wrappers/wrapper.js +++ b/src/wrappers/wrapper.js @@ -71,7 +71,7 @@ export default class Wrapper implements BaseWrapper { classes (): Array { // works for HTML Element and SVG Element const className = this.element.getAttribute('class') - let classes = className ? className.split(' ') : [] + let classes = className ? className.split(' ') : [] // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { const cssModuleIdentifiers = {} From cf9aa17e254babb56c6685b37fe219940a9efcbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Cunat?= Date: Tue, 27 Feb 2018 09:02:05 +0100 Subject: [PATCH 6/6] add unit test with svg element for classes --- test/specs/wrapper/classes.spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/specs/wrapper/classes.spec.js b/test/specs/wrapper/classes.spec.js index 2e79132ad..51dfbb522 100644 --- a/test/specs/wrapper/classes.spec.js +++ b/test/specs/wrapper/classes.spec.js @@ -20,4 +20,12 @@ describeWithShallowAndMount('classes', (mountingMethod) => { const wrapper = mountingMethod(ComponentWithCssModules) expect(wrapper.classes()).to.eql(['extension', 'color-red']) }) + + it('returns array of class names for svg element', () => { + const compiled = compileToFunctions('') + const wrapper = mountingMethod(compiled) + expect(wrapper.classes()).to.contain('a-class') + expect(wrapper.classes()).to.contain('b-class') + expect(wrapper.find('text').classes()).to.contain('c-class') + }) })