Jest and ValidationRules tests

Hello,

I’m trying to learn how Jest work and I’m trying to cover our ValidationRules we have set up in our SPA which runs with webpack and javascript.

We have a DOM filled with numbers from 0-15 and we have a rule to ensure our amount variable is between 0 and 15, quite simple.

But how do I write a test to try if the rules works?

We create our rules in:

attached() { 
  ValidationRules.customRule(
  // some rule
  )
  ValidationRules
    .ensure('amount').satisfiesRule('amountRule')
}

Numbers is an array with numbers of 0 to 15

<select value.bind="bag.selectedAmount" class="${!bag.selectedAmount && errors.length > 0 ? 'error-dropdown' : ''} form-control input regular-15-25 select-height"
                id="selectAmount">
                <option value="">Choose</option>
                <option repeat.for="number of numbers" model.bind="number">${number}</option>
             </select>

Do I need to stage the component? Can I just simple do something similar to sut.amountRule(‘amount’)?

Thanks in advance.

1 Like