From bcf580ecd5c4c61f58084bf9e490f2a9373584c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Cunat?= Date: Tue, 27 Feb 2018 22:22:41 +0100 Subject: [PATCH] fix: classes() for svg elements (#445) --- src/wrappers/wrapper.js | 4 +++- test/specs/wrapper/classes.spec.js | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wrappers/wrapper.js b/src/wrappers/wrapper.js index 309c6690f..8b8ca3780 100644 --- a/src/wrappers/wrapper.js +++ b/src/wrappers/wrapper.js @@ -69,7 +69,9 @@ 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(' ') : [] + // works for HTML Element and SVG Element + 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 = {} 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') + }) })