vue-add-globals

2.0.1 • Public • Published

vue-add-globals

Add globals to Vue. Use it in tests to mock global methods and properties.

Example

Adding a property and method to Vue

import addGlobals from 'vue-add-globals'
import Vue from 'vue'
 
const $someMethod = () => ({})
const someProp = 'prop'
addGlobals(Vue, {
  $someMethod: $someMethod,
  someProp: someProp
})
const Ctor = Vue.extend(TestComponent)
const vm = new Ctor().$mount()
 
t.is(vm.$someMethod, $someMethod)
t.is(vm.someProp, someProp)

Installation

npm install --save-dev vue-add-globals

Usage

  • Import 'vue-add-globals'
  • Call it with object of global properties to add
import addGlobals from 'vue-add-globals'
 
addGlobals(Vue, { $mockedMethod: mockedMethod })

You can keep the global Vue class clean by using Vue.extend():

import addGlobals from 'vue-add-globals'
import Vue from 'vue'
 
const freshVue = Vue.extend()
 
addGlobals(freshVue, { $mockedMethod: mockedMethod })

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.1
    4,530
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.1
    4,530
  • 2.0.0
    8
  • 1.0.1
    435
  • 1.0.0
    0

Package Sidebar

Install

npm i vue-add-globals

Weekly Downloads

842

Version

2.0.1

License

MIT

Last publish

Collaborators

  • eddyerburgh