[Vue.js] 단위 테스트 - VTU 첫 테스트

2022. 4. 18. 21:56공부/Vue.js

참조) Getting Started | Vue Test Utils (vuejs.org)

 

Getting Started | Vue Test Utils

Getting Started Welcome to Vue Test Utils, the official testing utility library for Vue.js! This is the documentation for Vue Test Utils v2, which targets Vue 3. In short: What is Vue Test Utils? Vue Test Utils (VTU) is a set of utility functions aimed to

test-utils.vuejs.org

외부 Vue 파일 가져와서 테스트

/tests/Example.vue 생성

이런식으로 vue test utils를 이용하여 Vue 파일을 mount시켜서 테스트할 수 있다.

mount() 함수는 wrapper 객체를 반환하는데 이를 직관적으로 wrapper 라는 변수에 담아서 사용한다.

wrapper 객체는 this 키워드를 제공하지 않는 대신 vm이라는 프로퍼티를 제공한다. this 처럼 사용하면 된다.

 

msg를 Changed로 바꿔보았다.

data를 수정할 수도 있다.

다만 이렇게 바꾸는 것은 테스트로서의 의미가 퇴색된다.

또한 반응성을 유지하지 못한다.

div 요소의 텍스트는 변하지 않고 그대로다.

반응성을 유지하려면 .setData() 메소드를 사용해야 한다. (비동기로 동작)