During testing, the instance of a class returns undefined

2

A bit of context.

  

I'm creating a plugin using tests and when using the instance of a class, it just does not pass the simplest test.

     

The plugin is an adapted copy of the Satellizer a well-known module that manages accreditation through tokens . The adaptation consists of converting it into a plugin of , use for the connection to the server and

asked by toledano 11.04.2017 в 23:09
source

1 answer

0

To properly test Vue you must create a Vue instance , previously configured. That is, in the test file, we upload the necessary files to run the tests:

let Vue = require('vue')
let expect = require('chai').expect
const plugin = require('../src/plugin/index')

We configure Vue, in this example, so that it does not send the advice

mensajeVue.config.productionTip = false
Vue.use(plugin)

and we proceed to create the instance of vue

let vm = new Vue()

In this instance the plugin is already there and we can do the tests that we have designed, for example:

describe('El archivo plugin', function () {
  it('debe existir', function () {
    expect(plugin).to.not.be.undefined
  })

  it('debe estar instalado', () => {
    expect(plugin.installed).to.be.true
  })

  it('debe tener la propiedad $acreditar', () => {
    expect(vm.$acreditar).to.not.be.undefined
  })

  it('debe tener la propiedad version', () => {
    const version = '0.1.0'
    expect(vm.$acreditar.version).to.equal('0.1.0')
  })
})
    
answered by 13.04.2017 в 01:34