Skip to content

Commit bcf580e

Browse files
jeffcunateddyerburgh
authored andcommitted
fix: classes() for svg elements (#445)
1 parent 85e9765 commit bcf580e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/wrappers/wrapper.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export default class Wrapper implements BaseWrapper {
6969
* Returns an Array containing all the classes on the element
7070
*/
7171
classes (): Array<string> {
72-
let classes = this.element.className ? this.element.className.split(' ') : []
72+
// works for HTML Element and SVG Element
73+
const className = this.element.getAttribute('class')
74+
let classes = className ? className.split(' ') : []
7375
// Handle converting cssmodules identifiers back to the original class name
7476
if (this.vm && this.vm.$style) {
7577
const cssModuleIdentifiers = {}

test/specs/wrapper/classes.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ describeWithShallowAndMount('classes', (mountingMethod) => {
2020
const wrapper = mountingMethod(ComponentWithCssModules)
2121
expect(wrapper.classes()).to.eql(['extension', 'color-red'])
2222
})
23+
24+
it('returns array of class names for svg element', () => {
25+
const compiled = compileToFunctions('<svg class="a-class b-class"><text class="c-class"/></svg>')
26+
const wrapper = mountingMethod(compiled)
27+
expect(wrapper.classes()).to.contain('a-class')
28+
expect(wrapper.classes()).to.contain('b-class')
29+
expect(wrapper.find('text').classes()).to.contain('c-class')
30+
})
2331
})

0 commit comments

Comments
 (0)