Skip to content

Commit

Permalink
fix: classes() for svg elements (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcunat authored and eddyerburgh committed Feb 27, 2018
1 parent 85e9765 commit bcf580e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/wrappers/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export default class Wrapper implements BaseWrapper {
* Returns an Array containing all the classes on the element
*/
classes (): Array<string> {
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 = {}
Expand Down
8 changes: 8 additions & 0 deletions test/specs/wrapper/classes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<svg class="a-class b-class"><text class="c-class"/></svg>')
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')
})
})

0 comments on commit bcf580e

Please sign in to comment.