Please ensure to provide a boolean value when using wrapper.setChecked() in Vue Test Utils

Working on a project with Vue, I have implemented some radio inputs:

  <label>
    <input
      v-model="myProperty"
      v-bind:value="true"
      name="myProperty"
      type="radio"
    > True
  </label>

  <label>
    <input
      v-model="myProperty"
      v-validate="input.rules ? input.rules : ''"
      v-bind:value="false"
      name="myProperty"
      type="radio"
    > False
  </label>

When testing the functionality using vue-test-utils and jest, I encountered an issue in selecting and assigning a value to my radio field:

let myProperty = wrapper.find('[name="myProperty"]')
myProperty.setChecked(false)

Although the documentation suggests this method should work, it resulted in an error message:

[vue-test-utils]: wrapper.setChecked() must be passed a boolean

Interestingly, setting the value as true worked fine. I also attempted setting the value as string 'false':

myProperty.setChecked('false')

But again, received the same error regarding passing a boolean value. So how can I correctly select the desired radio input in vue-test-utils when the value is set to false? What if the radio inputs have string values instead?

Answer №1

To ensure only one radio button is checked at a time, you must use the setChecked function on another radio input within the group. This will automatically uncheck all other radio buttons in the same group:

wrapper.find('[name="other property"]').setChecked(true)

It's important to note that Vue Test Utils does not allow setting a radio button's checked attribute to false. This prevents creating a scenario where no radio buttons are selected, which is not possible for users to do manually.

If you believe there is a need to reconsider this design choice, please submit a feature request on the Vue Test Utils GitHub repository.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The preventDefault() method is failing to work when submitting a form

Here is a form that processes a password recovery script requested by the user. <form class="forget-form" id="forget-form" action="datacenter/functions/passwordRecovery.php" method="POST"> <h3 class="font-green">Forgot your password?</h ...

How do I access the current locale when generating routes in Nuxt i18n?

I've run into a bit of issue while trying to generate dynamic routes in Nuxtjs. I have a collection of products that I fetch from an API and I'm creating individual pages for each of them. Everything is functioning smoothly for the default local ...

Using an image as the background for a three.js scene may cause it to appear distorted

I am struggling with setting an image as a background for my scene without it becoming blurry. I have attempted to use the following code: textureLoader.load("images/background/space.png", function(t) { scene.background = t; }); The problem arises when ...

What strategies can be utilized to condense code when needing to adjust a className based on various props?

I am looking to condense this code, particularly the [if~else if] block, in order to dynamically change a className based on different props passed. export default function Button(props) { const { name, height, color, bgColor } = props; let className = ...

Is there a way to rearrange the selectpicker selection based on the user's choice?

I'm in the process of setting up a selectpicker that allows users to choose multiple options from a dropdown list. The challenge is that the values extracted by my backend need to be in the order of user selection, rather than the original order of th ...

How can one determine when an animation in Three.js has reached its conclusion?

When I write code like this: function renderuj(){ scene.renderer.setClearColor(0xeeeeee, 1); ob1.animation.update(0.5); ob2.animation.update(0.5); scene.renderer.render(scene.scene, scene.camera); animationFram = reques ...

Is there a way to eliminate the impact of Jquery Document Click Listeners on a React Element?

We are currently in the process of rewriting parts of our legacy web app using React incrementally. As a result, we are unable to completely eliminate various document listeners that are scattered throughout the code. The presence of these listeners on dif ...

Controller experiencing issues with Ajax passing null value

My webpage features a dropdown menu with a list of ID's to choose from. When a customer selects an option, it should update the price total displayed on the page. To achieve this functionality, I'm working on implementing an AJAX call that will u ...

Using a for loop to open several tabs simultaneously in TypeScript

Recently, I attempted to launch a new tab using the code snippet below: window.open("wwww.stackoverflow.com", "_blank"); Although this method worked perfectly fine when opening a single URL, things took an unexpected turn when I ...

Is your custom login form in Web2py not submitting properly?

My attempt to customize the login form for web2py has hit a roadblock. Despite adding the necessary fields and submit button, nothing seems to be happening. Here's what the code in the form's view looks like: {{include 'web2py_ajax.html&apo ...

Combining backend webpack with Vue-CLI 3 for seamless integration

As I work on a full-stack application with Vue-CLI 3, the backend side is built in TypeScript which requires compilation. Currently, I am running the backend app directly using ts-node, but I am looking for a cleaner solution to bundle the backend code int ...

The constructor window.CCapture is not valid in Node.js environment

Can anyone help me figure out how to load CCapture in Node.js without using a headless browser for recording canvas stream? Every time I try, I keep running into the error message saying "window.CCapture is not a constructor." If you are familiar with the ...

"Utilizing Axios to convey JSON data into Vue Js: A Step-by-Step Guide

After saving my JSON data in a JS file for Vue, I encountered an issue with accessing it and getting my HTML v-for condition to work properly. The method described in the Vue.js documentation didn't help me fetch and execute the JSON data. Could someo ...

I am having issues with the Load More Posts Ajax Button on my WordPress site and it is

I'm trying to display more posts when a button is clicked. Upon inspecting and checking the network, everything seems to be working fine, or at least that's what I assume. https://i.sstatic.net/44VS1.jpg https://i.sstatic.net/KEkiz.jpg I&apos ...

Attention: It is not possible to update the React state on a component that is not mounted. Please use the useEffect cleanup function

Can you assist with solving this issue? https://i.sstatic.net/yKFzr.png //ReviewProductDetail.jsx : Initially, the page was populated from this particular component import React, { useEffect, useState } from 'react'; import RatingCardProductD ...

Implementing this type of route in Vue Router - What are the steps I should take?

I am currently delving into Vue and working on a project that involves creating a Vue application with a side menu for user navigation throughout the website. Utilizing Vue Router, my code structure looks like this: <template> <div id="app ...

The NodeList returned by querySelectorAll is not defined

One issue I encountered in this code snippet is that the 'questions' array is empty. I expected the 'ol li' selector to target all list items within ordered lists. Another problem I faced was the inability to assign an id to the array, ...

Is there a way to delete a table's row using JavaScript?

Hey there, total newbie to coding here. I'm working on a simple to do list project. The adding function is working great, and here's the code for it: let salvar = document.getElementById("salvar") let remove = document.getElementById("remove ...

Enhancing Functionality in JQuery UI Autocomplete

Here is my jQuery script code that I have implemented: <script type="text/javascript"> var months = ['01 - January', '02 - February', '03 - March', '04 - April', '05 - May', '06 - June& ...

The video on Videojs fails to show up on the screen

Currently utilizing the most recent version of videojs. Referencing this example http://jsfiddle.net/swinginsam/NWbUG/#share Access source code Having trouble identifying the issue. <!DOCTYPE html> <html> <head> <title>Video.j ...