bulky-sundown-74498
07/08/2021, 2:28 PMancient-wire-34126
07/09/2021, 1:54 PMrhythmic-army-81251
07/12/2021, 3:38 PMts
describe('MultiTreePicker', () => {
it('should be visible', () => {
const properties = ...;
mount(MultiTreePicker, {
propsData: { properties },
cssFile: CSS.default,
}).then(() => {
(Cypress.vue as unknown as ShowModalComponent).showModal();
});
});
it('should be visible 2', () => {
const properties = ...;
mount(MultiTreePicker, {
propsData: { properties },
cssFile: CSS.default,
}).then(() => {
(Cypress.vue as unknown as ShowModalComponent).showModal();
});
});
});rhythmic-army-81251
07/12/2021, 3:38 PMrhythmic-army-81251
07/12/2021, 3:39 PMCypress.vue being undefinedrhythmic-army-81251
07/12/2021, 3:39 PMrhythmic-army-81251
07/12/2021, 3:39 PM[Vue warn]: Failed to resolve directive: interactrhythmic-army-81251
07/12/2021, 3:39 PMVue.directive('interact', interactDirective); before the testrhythmic-army-81251
07/12/2021, 3:40 PMrhythmic-army-81251
07/12/2021, 3:40 PMit out of the describe block and into another describe (same file) it worksbreezy-australia-64868
07/12/2021, 4:31 PMspy, but keep getting Attempted to wrap undefined property onConfirm as function. I'm console logging the vue instance Cypress.vue right before creating the spy and the method is there. Trying it like const onConfirm = cy.spy(Cypress.vue, 'onConfirm');. Any idea what I'm doing wrong, or if there's a better way to make sure a method was called? Thanks!wonderful-match-15836
07/12/2021, 4:48 PM.vue() is a command added the way that @User showed me from one of Jessica's repos, you can see some context here: https://discord.com/channels/755913899261296641/755921440359841852/832621748028440648
findAndSelectCameraOption() // this just finds the thing where clicking it should emit an event
.vue()
.then((wrapper) => {
expect(wrapper.emitted('item-selected')).to.have.length(1);
});
So grabbing that wrapper and using that for your spies/assertions/whatever might put you in more familiar territory, and make any vue-test-utils examples easier to translate to cypress CT context, if you really do need to get into the weeds of component behavior.breezy-australia-64868
07/12/2021, 4:50 PMonConfirm function as a prop, so the test should make sure that that function was called at the right timewonderful-match-15836
07/12/2021, 5:01 PMwrapper.props().onConfirm. I suppose it's personal preference but I'd normally expect a library component to just emit a "confirmed" event and let the user worry about running the handler. But you might be doing something fancy that I'm not thinking of.
Also I seem to run into this a lot lately so just in case - how are you logging Cypress.vue? It seems possible your spy is evaluated before Cypress.vue is actually fully up and running. If you log Cypress.vue.onConfrim instead at that same point, is it defined? I've been tripped up a ton by logging objects before they have been modified, but only expanding them in the console after they've been modifiedbreezy-australia-64868
07/12/2021, 5:05 PMwonderful-match-15836
07/12/2021, 5:09 PMconsole.log actually ran. So logging before/after the const onConfirm assignment is all the same in that case. Anyhoo I gotta run but I hope some of this was helpful, I have really liked component testing once I got everything running rightbreezy-australia-64868
07/12/2021, 5:28 PMable-kangaroo-37061
07/12/2021, 6:16 PMrhythmic-army-81251
07/13/2021, 2:58 PMrhythmic-army-81251
07/13/2021, 2:58 PMrhythmic-army-81251
07/13/2021, 3:00 PM// Parent.vue
<template>
<div>
<Child v-if="condition" />
</div>
</template>
// Child.vue
<template>
<div v-custom-directive>
Hello
</div>
</template>rhythmic-army-81251
07/13/2021, 3:00 PMrhythmic-army-81251
07/13/2021, 3:00 PMrhythmic-army-81251
07/13/2021, 3:01 PMvue.runtime.esm.js:620 [Vue warn]: Failed to resolve directive: custom-directive
(found in <Child> at src/Child.vue)gorgeous-refrigerator-7329
07/16/2021, 9:43 AMjs
it('emits "increment" event on click', () => {
const spy = cy.spy()
Cypress.vue.$on('increment', spy)
cy.get('button')
.click()
.click()
.then(() => {
expect(spy).to.be.calledTwice
})
})
})
This works with Vue 2, but in Vue 3 I get the following error:
Cypress.vue.$on is not a function
Searching through issues didn't yield any results. Am I doing something wrong or should I open GH issue for this? Thank you.
json
"cypress": "^7.7.0",
"@cypress/vue": "^3.0.1",bland-advantage-37100
07/16/2021, 1:48 PMbulky-sundown-74498
07/16/2021, 2:08 PMbland-advantage-37100
07/16/2021, 2:10 PMgorgeous-refrigerator-7329
07/16/2021, 2:21 PMgorgeous-refrigerator-7329
07/19/2021, 5:38 AMexpect(Cypress.vueWrapper.emitted("click")[0][0]).to.be.calledOnce. The key is to bind the event to the spy in the mount function using the attrs property.
For example to spy on click event just do this:
js
// Component.spec.js
const spy = cy.spy();
mount(Component, {
attrs:
onClick: spy
}
})
// Then you can continue to work with the spy as usual.
cy.get("button")
.click()
.then(() => expect(spy).to.be.calledOnce)
Or the spy can be added after mount using setProps
js
await Cypress.vueWrapper.setProps({onClick: spy});