https://github.com/eddyerburgh/vue-add-globals
Add globals to a Vue instance 🌎
https://github.com/eddyerburgh/vue-add-globals
Last synced: about 1 year ago
JSON representation
Add globals to a Vue instance 🌎
- Host: GitHub
- URL: https://github.com/eddyerburgh/vue-add-globals
- Owner: eddyerburgh
- License: mit
- Created: 2017-05-03T19:26:29.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T20:22:51.000Z (over 3 years ago)
- Last Synced: 2024-04-14T23:58:59.669Z (about 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 582 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```js
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
```shell
npm install --save-dev vue-add-globals
```
## Usage
* Import 'vue-add-globals'
* Call it with object of global properties to add
```js
import addGlobals from 'vue-add-globals'
addGlobals(Vue, { $mockedMethod: mockedMethod })
```
You can keep the global Vue class clean by using `Vue.extend()`:
```js
import addGlobals from 'vue-add-globals'
import Vue from 'vue'
const freshVue = Vue.extend()
addGlobals(freshVue, { $mockedMethod: mockedMethod })
```