Unit Testing with PrimeVue

UI Components for Vue
Post Reply
richardshergold
Posts: 3
Joined: 13 Oct 2021, 14:16

13 Oct 2021, 14:27

Is there a trick to writing Unit Tests when using PrimeVue components?

(I'm new to Vue, PrimeVue AND Unit Testing!)

I have an InputText component in my template like this:

Code: Select all

<InputText
data-testid="new-delivery-method"
size="50"
id="deliveryMethod"
type="text"
placeholder="New Delivery Method"
v-model="newDeliveryMethod"
/>
I am writing the following in my unit test:

Code: Select all

const inputBox = wrapper.find('[data-testid="new-delivery-method"]');
await inputBox.setValue("Our New Method")
but I get the following error:

Code: Select all

wrapper.setValue() cannot be called on INPUTTEXT" ?
I also tried this:

Code: Select all

const inputBox = wrapper.find('[data-testid="new-delivery-method"]');
const inputBox =  wrapper.find('InputText')
inputBox.element.value = 'Our New Method';
inputBox.trigger('input')
but that didn't seem to set the value.

What is the correct way of setting the value of my InputText component in a unit test?

Can anyone offer any assistance??

thanks

richardshergold
Posts: 3
Joined: 13 Oct 2021, 14:16

14 Oct 2021, 16:46

I solved this. I had to use the Global Components option to include the PrimeVue component when mounting the component I was unit testing.

Post Reply

Return to “PrimeVue”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests