Javascript Vue.js Avoriaz单元测试在使用Vue-i18n时生成翻译警告 总结

Javascript Vue.js Avoriaz单元测试在使用Vue-i18n时生成翻译警告 总结,javascript,unit-testing,vue.js,vue-i18n,avoriaz,Javascript,Unit Testing,Vue.js,Vue I18n,Avoriaz,我正在使用i18n和Vue.js组件进行单元测试。我收到很多警告,因为我无法修复未翻译的字符串。我怎样才能摆脱这些警告 警告示例 “[vue-i18n]无法转换键路径“description.first”的值。 使用keypath的值作为默认值。” 测试设置 测试组件 {{$t('button.first')} 导出默认值{ i18n:{ 信息:{ 嗯:{ 'description.first':'输入名称', “label.first”:“Name*”, 'description.secon

我正在使用i18n和Vue.js组件进行单元测试。我收到很多警告,因为我无法修复未翻译的字符串。我怎样才能摆脱这些警告

警告示例 “[vue-i18n]无法转换键路径“description.first”的值。 使用keypath的值作为默认值。”

测试设置 测试组件

{{$t('button.first')}
导出默认值{
i18n:{
信息:{
嗯:{
'description.first':'输入名称',
“label.first”:“Name*”,
'description.second':'输入密码',
'label.second':'Password*',
'按钮。第一个':'创建'
},
de:{
'description.first':'Gebe einen Namen ein',
“label.first”:“Name*”,
'description.second':'Gebe ein Passwort ein',
'label.second':'Passwort*',
“figcaption.figcaption.first”:“Du kannst einen dieser Nutzer wählen,嗯,我是einzuloggen。”,
“button.first”:“Erstellen”
}
}
},
计算:{
用户:{
得到(){
返回此。$store.state.user
}
},
姓名:{
得到(){
返回此项。$store.state.user.name
},
/**
*@param name
*/
集合(名称){
此.$store.commit('SET\u USER\u NAME',NAME)
}
},
密码:{
得到(){
返回此。$store.state.user.password
},
/**
*@param密码
*/
设置(密码){
此.$store.commit('SET\u USER\u PASSWORD',PASSWORD)
}
}
},
方法:{
创建(){
this.store.dispatch('saveUser',this.user)
}
}
}

您需要创建对象
i18n
,然后注入它:

// This object containing your translated strings
const messages = {/*...*/};
const i18n = new VueI18n({locale: 'en', messages});

const wrapper = mount(Register, {
    store,
    i18n
})
<template>
  <div class="row justify-content-md-center">
    <div class="col-6">
      <b-form-fieldset
        :description="$t('description.first')"
        :label="$t('label.first')"
        :label-size="1">
        <b-form-input v-model="name"></b-form-input>
      </b-form-fieldset>
      <b-form-fieldset
        :description="$t('description.second')"
        :label="$t('label.second')"
        :label-size="1">
        <b-form-input v-model="password" type="password"></b-form-input>
      </b-form-fieldset>
      <b-button variant="outline-success" size="sm" @click="create">{{ $t('button.first') }}</b-button>
    </div>
  </div>
</template>

<script>
  export default {
    i18n: {
      messages: {
        en: {
          'description.first': 'Enter a name',
          'label.first': 'Name *',
          'description.second': 'Enter a password',
          'label.second': 'Password *',
          'button.first': 'Create'
        },
        de: {
          'description.first': 'Gebe einen Namen ein',
          'label.first': 'Name *',
          'description.second': 'Gebe ein Passwort ein',
          'label.second': 'Passwort *',
          'figcaption.first': 'Du kannst einen dieser Nutzer wählen, um dich einzuloggen.',
          'button.first': 'Erstellen'
        }
      }
    },

    computed: {
      user: {
        get () {
          return this.$store.state.user
        }
      },

      name: {
        get () {
          return this.$store.state.user.name
        },

        /**
         * @param name
         */
        set (name) {
          this.$store.commit('SET_USER_NAME', name)
        }
      },

      password: {
        get () {
          return this.$store.state.user.password
        },

        /**
         * @param password
         */
        set (password) {
          this.$store.commit('SET_USER_PASSWORD', password)
        }
      }
    },

    methods: {
      create () {
        this.$store.dispatch('saveUser', this.user)
      }
    }
  }
</script>
// This object containing your translated strings
const messages = {/*...*/};
const i18n = new VueI18n({locale: 'en', messages});

const wrapper = mount(Register, {
    store,
    i18n
})