N
N
nurdus2018-11-13 23:37:24
JavaScript
nurdus, 2018-11-13 23:37:24

How to write unit tests without (or replacing) dependencies?

Good evening.
This is my first time writing a unit test, so please don't throw tomatoes at me =)
There is "example.spec.js" (taken from Hello Word)

import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
import PageMain from '@/components/PageMain.vue'
describe('PageMain.vue', () => {
  it('renders props.msg when passed', () => {
    const msg = 'new message'
    const wrapper = shallowMount(PageMain, {
      propsData: { msg }
    })
    expect(wrapper.text()).to.include(msg)
  })
})

There is a component that needs to be tested "PageMain.vue":
<template>
  <f7-page>
    <CardInfo :article="$locale({i: 'CONTENT.main'})"></CardInfo>
  </f7-page>
</template>
//...

When launched, the test swears at "$locale", it does not see it (which is logical, since I wrote it a level higher in main.js). The question is how to solve the problem? If you are interested/needed, then the main.js code is below:
import Vue from 'vue'
import App from './App.vue'

import Localize from 'v-localize'
Vue.use(Localize)

let localize = Localize.config({
  default: 'ru',
  available: ['ru', 'en'],
  fallback: '?????',
  localizations: {
    'en': EN,
    'ru': RU
  }
})

new Vue({
  localize,
  render: h => h(App)
}).$mount('#app')

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question