Page 1 of 1

Unit Testing with PrimeVue

Posted: 13 Oct 2021, 14:27
by richardshergold
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

Re: Unit Testing with PrimeVue

Posted: 14 Oct 2021, 16:46
by richardshergold
I solved this. I had to use the Global Components option to include the PrimeVue component when mounting the component I was unit testing.