-
Notifications
You must be signed in to change notification settings - Fork 0
Vue Jest
Kyle Coberly edited this page Mar 22, 2020
·
1 revision
- Testing library is
@vue/test-utils - Mount comonents with
shallowMountandmount
shallowMount(component, {
propsData: {},
data: {},
})
.find(selector).findAll(selector)-
.setData(),.setProps() .props()
.trigger(event)-
.setValue()/setChecked()/setSelected()
.text().exists().emitted(event).contains(selector).isVisible().classes().attributes.()
Escape hatches:
-
.vm- Access to the component object -
.element- Access to the underlying DOM element -
.html- Access to the underlying HTML element
import { shallowMount } from "@vue/test-utils";
import HelloWorld from "@/components/HelloWorld.vue";
describe("Emitting", () => {
it("emits", () => {
const component = shallowMount(HelloWorld);
component.find("button").trigger("click");
expect(component.emitted().pizza).toBeTruthy();
});
});