-
단위 테스트 - mount 와 shallowMount테스트/단위 테스트 (Vue) 2021. 9. 7. 03:04
단위 테스트 - mount 와 shallowMount
Parent.vue
<template> <h1>Parent</h1> <Child msg="ITBlue" /> </template>
<script> import Child from './Child' export default { components: { Child } } </script>
Child.vue
<template> <div>Child: {{ msg }}</div> </template>
<script> export default { props: { msg: { type: String, default: '' } } } </script>
Parent.test.js
/* import { mount } from '@vue/test-utils' import Parent from './Parent' test('Mount', () => { const wrapper = mount(Parent) // Received: "<h1>Parent</h1> <div>Child: ITBlue</div>" expect(wrapper.html()).toBe('') }) */ import { shallowMount } from '@vue/test-utils' import Parent from './Parent' test('Mount', () => { // shallowMount - 얕은 연결 const wrapper = shallowMount(Parent) // Received: "<h1>Parent</h1> <child-stub msg=\"ITBlue\"></child-stub> expect(wrapper.html()).toBe('') }) // mount - 하위의 컴포넌트 모두 연결 // shallowMount - 하위의 컴포넌트 가짜로 만들어서 연결을 하는 척만 함
'테스트 > 단위 테스트 (Vue)' 카테고리의 다른 글
단위 테스트 - Search 컴포넌트 (0) 2021.09.08 단위 테스트 - Header 컴포넌트 (0) 2021.09.07 단위 테스트 - VTU 테스트 및 API (0) 2021.09.07 단위 테스트 - 모의(Mock) 함수 (0) 2021.09.05 단위 테스트 - 비동기 테스트 (0) 2021.09.04