VueJS - 使用 vue-test-utils 进行单元测试给出错误 - TypeError: _vm.$t is not a function [英] VueJS - Unit testing with vue-test-utils gives error - TypeError: _vm.$t is not a function

查看:84
本文介绍了VueJS - 使用 vue-test-utils 进行单元测试给出错误 - TypeError: _vm.$t is not a function的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Vuejs 相对较新并测试其组件.使用 vue-test-utils 和 jest 进行测试.得到以下错误测试日志

Relatively new to Vuejs and testing its components. Using vue-test-utils and jest for testing. Getting following error test log

.vue 文件由模板、组件和样式组成.下面是 SignupLayout.vue 出错的部分 -

The .vue file consists of template, component and styling. Below is the part of the SignupLayout.vue that gets error -

<style lang="sass">
@import '../stylesheets/colors'
html[path="/signup"], html[path="/login"]
  height: 100%
  background-image: url("../assets/background.jpg")
  background-size: cover
  background-position: center
  background-repeat: no-repeat
  overflow: hidden

  #signup-layout
    #change-language-button
      .lang-menu
        color: $alto

</style>

测试文件 -

import Vue from 'vue';
import Vuex from 'vuex'
import SignupLayout from '../src/components/SignupLayout.vue';
import { mount, shallow, createLocalVue } from '@vue/test-utils';

const localVue = createLocalVue()

localVue.use(Vuex)

jest.resetModules()

describe('Signup.test.js', () => {
    let cmp
    let actions
    let store
    let getters
    let state

    beforeEach(() => {


        state = {
            email: 'abc@gmail.com'
        }
 
        getters = {
            CURRENT_USER_EMAIL: state => state.email
        }

        store = new Vuex.Store({
            getters
        })


    })

    it('has received ["Login"] as the title property', () => {
        cmp = shallow(SignupLayout, {
            store,
            localVue,
            propsData: {
                title: ['Login']
            },
            data: {
                email: 'abc@dsf.com'
            }
        })
        cmp.update()
        expect(cmp.vm.title).toEqual(['Login'])
    })


})

对 $t 与 sass 有什么关系感到困惑.任何帮助,将不胜感激.现在卡在这里一段时间了.如果需要更多详细信息,请告诉我.提前致谢

Confused as to what has $t got to do with sass. Any help would be appreciated. Stuck here for a while now. Let me know if more details needed. Thanks in advance

推荐答案

错误不在