Last active
April 8, 2022 11:05
-
-
Save eddyerburgh/918af21eb465eba04b8401f2063124f8 to your computer and use it in GitHub Desktop.
vue-test-utils hasClass example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
How to check if a class does not exist in element
something like
expect(div.hasClass('foo')).toBe(false)
how to do it using classes()
expect(div.classes()).not.toContain('foo')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It appears that
hasClass()
will be deprecated in test-utils v1. The new prefered method is to use "classes()" instead, like so:hasStyle()
will also be deprecated: