Skip to content

Instantly share code, notes, and snippets.

@eddyerburgh
Last active April 8, 2022 11:05
Show Gist options
  • Save eddyerburgh/918af21eb465eba04b8401f2063124f8 to your computer and use it in GitHub Desktop.
Save eddyerburgh/918af21eb465eba04b8401f2063124f8 to your computer and use it in GitHub Desktop.
vue-test-utils hasClass example
import { mount } from 'vue-test-utils'
import Component from '@/components/ComponentToTest'
const wrapper = mount(ComponentToTest)
// Traversal
const Foo = wrapper.find(Foo)
const divs = wrapper.findAll('div')
const div = divs.at(0)
// Actions
Foo.setData({ foo: true })
Foo.setProps({ bar: true })
div.trigger('click')
// Assertions
expect(Foo.hasProp('bar', 'foobar')).toBe(true)
expect(div.hasClass('foo')).toBe(true)
expect(div.hasStyle('color', 'red')).toBe(true)
expect(div.is('.foo')).toBe(true)
@mukulkhanna
Copy link

mukulkhanna commented Jun 17, 2018

@Uthpala

expect(div.classes()).not.toContain('foo')

@niczak
Copy link

niczak commented Feb 17, 2021

@Uthpala

expect(div.classes()).not.toContain('foo')

This is an oldie but a goodie, thank you @Uthpala!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment