programing

Vuex를 올바르게 테스트하는 방법

prostudy 2022. 6. 26. 09:44
반응형

Vuex를 올바르게 테스트하는 방법

Vuex 스토어 테스트에 도움이 필요합니다(이 작업은 지금까지 한 번도 해본 적이 없고, 안타깝게도 이해하기 어렵습니다).

두 개의 버튼이 있는데, 두 개의 다른 함수를 호출하여 무언가를 반환하는지 테스트해야 합니다.

단추:

...
<input class="main-form__login-submit" v-if="this.loginBtn" type="submit" @click="handleLogin" value="Войти" />

<input class="main-form__login-submit main-form__login-session" v-if="this.showLogoutEverywhereBtn" type="button" @click="websocketAuth" value="Выйти из других окон" />
...

방법:

...
methods: {
        handleLogin(e) {
            e.preventDefault()
            this.$store.dispatch('login', this.loginForm)
                .then((response) => {
                    console.log('login page response: ', response)
                    if (response.id_user !== undefined) {
                        this.$router.push({ path: '/' })
                    }
                })
                .catch((e) => {
                    console.log('ты внутри ошибки: ', e);
                });
        },
        websocketAuth(e) {
            e.preventDefault()
            console.log('login:  ', this.loginForm.username, this.loginForm.password)
            this.$store.dispatch("logoutEverywhere", {
                user_login: this.loginForm.username,
                user_password: this.loginForm.password
            })
                .then((resp) => {
                    let data = { userId: resp, page: 'login' }
                    socketUrl.emit('logoutEverywhere', data, (flag) => {
                    if(flag) {
                        this.$store.dispatch('duplicateLoginClear')
                    }
                    console.log(flag)
                    })

                    console.log('1 ', resp)
                })
        }
    }
...

잘 부탁드립니다!

jeast mock을 사용해야 합니다(jeast를 사용하는 경우).

간단한 튜토리얼을 소개합니다.

https://codeburst.io/a-pattern-for-mocking-and-unit-testing-vuex-actions-8f6672bdb255

언급URL : https://stackoverflow.com/questions/59248613/how-to-test-vuex-correctly

반응형