Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catching emitted value from a component using defineEmits #1

Closed
Smrtnyk opened this issue Sep 14, 2024 · 2 comments
Closed

Catching emitted value from a component using defineEmits #1

Smrtnyk opened this issue Sep 14, 2024 · 2 comments

Comments

@Smrtnyk
Copy link

Smrtnyk commented Sep 14, 2024

Is it possible to catch emitted value from a component after submit button on a form in the component is clicked?

@hezhengxu2018
Copy link

...getElementLocatorSelectors(baseElement),

maybe should return the wrapper here, and use the findComponent function of vue-test-utils to get the componet you need.

@Smrtnyk
Copy link
Author

Smrtnyk commented Sep 23, 2024

Actually I am able to use screen.emitted, and it contains the entry for the emitted event and its values

for example a test like this works for me

it(`emits "delete-item" event when delete button is clicked`, async () => {
        const deleteButton = page.getByAltText("Delete Chocolate Bar");
        expect(deleteButton.elements().length).toBe(1);

        await userEvent.click(deleteButton);

        const emittedEvents = screen.emitted("delete-item");
        expect(emittedEvents).toBeTruthy();
        expect(emittedEvents.length).toBe(1);
        expect(emittedEvents[0][0]).toStrictEqual(sampleItems[1]);
    });

@Smrtnyk Smrtnyk closed this as completed Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants