[Vuejs]-Vue.js vuetify : test-utils w Jest how to match text when using icon

0👍

One technique is to wrap the <v-btn>‘s text content in a <span>, and use wrapper.find(selector) to select the <span> to get its text:

foo.vue template:

<v-btn>
  <span class="text">STOP!</span>
  <v-icon>pause_circle_outline</v-icon>
</v-btn>

foo.spec.js

it('contains the expected text', () => {
  expect(wrapper.find('.text').text()).toEqual('STOP!');
});

demo

Leave a comment