0

I'm writing a test for Vuetify v-autocomplete wrapper component which checks displayed error message on blur. However error output shows that input select remains open and base element has focus class. I can't figure out what I'm doing wrong. Test code looks like:

it('should display error if field is empty', async () => {
    const { queryByLabelText, queryByText } = renderWithVuetify(MyComponent);

    await fireEvent.click(queryByLabelText('Label')); // Open v-autocomplete input select
    await fireEvent.click(document); // Should 'blur' input. Tried different elements here like document.body, Vuetify app root etc. Even dummy element next to v-autocomplete

    expect(queryByText('This field is required')).not.toBeNull();
});

2 Answers 2

2

You can use:

document.activeElement.blur();

to remove all focused elements.

Sign up to request clarification or add additional context in comments.

Comments

0

It turned out in the old Vuetify version ClickOutside directive checks event isTrusted property, which is obviously set to false if event is dispatched programmatically. Updating vuetify or hacking addEventListener resolves the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.