Appendix C. Exercise answers

This appendix provides the answers to the end-of-chapter exercises.

Chapter 2

1

test('renders Hello, World!', () => {
  const wrapper = shallowMount(TestComponent)
  expect(wrapper.text()).toContain('Hello, World!')
})

2

shallowMount

Chapter 3

1

test('renders item.author, () => {
  const item = {
    author: 10
  }
  const wrapper = shallowMount(Item, {
    propsData: { item }
  })
  expect(wrapper.text()).toContain(item.author)
})

test('renders item.score, () => {
  const item = {
    score: 10
  }
  const wrapper = shallowMount(Item, {
    propsData: { item }
  })
  expect(wrapper.text()).toContain(item.score)
})

2

import Child from 'child' test('renders Child', () => { const wrapper = shallowMount(TestComponent) expect(wrapper.find(Child).props().testProp).toBe('some-value') ...

Get Testing Vue.js Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.