diff --git a/src/wrappers/wrapper.js b/src/wrappers/wrapper.js index 5df404037..96a4ac8d4 100644 --- a/src/wrappers/wrapper.js +++ b/src/wrappers/wrapper.js @@ -98,11 +98,18 @@ export default class Wrapper implements BaseWrapper { * Asserts wrapper has a class name */ hasClass (className: string) { - if (typeof className !== 'string') { + let targetClass = className + + if (typeof targetClass !== 'string') { throwError('wrapper.hasClass() must be passed a string') } - return !!(this.element && this.element.classList.contains(className)) + // if $style is available and has a matching target, use that instead. + if (this.vm && this.vm.$style && this.vm.$style[targetClass]) { + targetClass = this.vm.$style[targetClass] + } + + return !!(this.element && this.element.classList.contains(targetClass)) } /** diff --git a/test/resources/components/component-with-css-modules.vue b/test/resources/components/component-with-css-modules.vue new file mode 100644 index 000000000..946af93fe --- /dev/null +++ b/test/resources/components/component-with-css-modules.vue @@ -0,0 +1,15 @@ + + + + + diff --git a/test/unit/specs/mount/Wrapper/hasClass.spec.js b/test/unit/specs/mount/Wrapper/hasClass.spec.js index d5851d002..ee05d1c0c 100644 --- a/test/unit/specs/mount/Wrapper/hasClass.spec.js +++ b/test/unit/specs/mount/Wrapper/hasClass.spec.js @@ -1,3 +1,4 @@ +import ComponentWithCssModules from '~resources/components/component-with-css-modules.vue' import { compileToFunctions } from 'vue-template-compiler' import mount from '~src/mount' @@ -39,4 +40,10 @@ describe('hasClass', () => { expect(fn).to.throw().with.property('message', message) }) }) + + it('returns true when element contains class name mapped in css modules', () => { + const wrapper = mount(ComponentWithCssModules) + + expect(wrapper.hasClass('color-red')).to.equal(true) + }) })