I have a form setup using vue.js and v-select
for a currency dropdown. I'm attempting to create a unit test to make sure the current value of the v-select is set to the computed value price_currency
Here is the vue code for the selector
<v-select
name="price_currency"
:value="price_currency"
@input="value => this.updateValue('price_currency', value)"
:options="currencies"
v-validate="validate.select"
:selectOnTab="true">
</v-select>
the :value
is set to price_currency
which is a computed value. In the unit tests, I can use the find method on the v-select
which will return the element, but because it's a vue component and not an actual <select>
the value
element is not set, which means I can't test for it.
How can I write a unit test for the above v-select
which will confirm that the field is set to the computed value of price_currency
? Additionally, I want to test that when price_currency
is updated so is the value on the v-select, but likely once I see an example of testing the value the rest will fall into place.
This seems like a fairly simple test, but I can't find anywhere in the documentation or online a good example of how this can be done.
For my unit tests, I am using VueTestUtils and Jest.
I did this:
This is how my Vue template code looks like:
And this is how the rendered HTML looks like when I mount the page and I call wrapper.html(), after it has already selected an option called
lorem
:Note that I prefer a more integration-oriented style of Jest testing, so I am making assertions for the contents of the page rather than the values in the models, this is because I feel like it provides better coverage. If you prefer to test only the values in the models then you might be able to find an example in the unit tests of V-Select itself.