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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.