lundi 2 novembre 2020

Vue.js unit jest test a component that has been bound

I'm trying to test a child component that has been bound, and it gives me an error where it basically doesn't find a data that comes from its parent component.

the parent component loops an array and passes the results (:slotData="slot") to the child (EventDate) component:

       <th
          ref="heading"
          v-for="slot in event.Slots"
          :key="slot.id"
          :class="slot.isChecked ? 'b-checked' : ''"
        >
          <EventDate :slotData="slot"></EventDate>
        </th>

in the child component I print the data passed through props: { slotData: Object }

  <div class="event-date-number">
   
   <small>/</small>
  </div>

the problem arises when I go to perform the unit test, it tells me: TypeError: Cannot read property 'startDate' of undefined

Now it doesn't matter what I want to do in the test. Whatever I want to do, it gives me this problem, I think because the past data comes from the parent component and not from the component I am testing ... how can I solve?

Aucun commentaire:

Enregistrer un commentaire