many-musician-13324
03/05/2023, 2:09 PMCustomDialog component with an exposed showDialog method, but I can't call it from the test. I tried using the vue test-utils wrapper https://docs.cypress.io/guides/component-testing/vue/examples#Customizing-cymount but I can't get it working.
Any help would be appreciated! 🙂wonderful-match-15836
03/07/2023, 12:44 AMjs
describe('<CustomDialog />', () => {
it('renders', () => {
cy.mount(CustomDialog).then(({component}) => {
component.$refs.customDialog.showModal()
})
})
})
Since you can call the showModal() method on the native HTML dialog element, you can avoid going through the vm and just grab the template ref.
Or you could avoid even caring about the component and do something like
js
cy.get('dialog').then(([el]) => el.showModal())
I think things made available with defineExpose work a little differently than, say, the same function defined under methods in the options API.
After tinkering for a bit I haven't quite figured out how to access those from the Cy component test, but there's likely a way, and we should document the pattern.many-musician-13324
03/07/2023, 9:26 AMwonderful-match-15836
03/07/2023, 8:59 PMmethods, you can have both <script> and <script setup> in the same SFC if you want.many-musician-13324
03/07/2023, 9:14 PM