Registry / testing / vue-add-globals

vue-add-globals

JSON →
library2.0.1jsnpmunverified

Vue Add Globals provides a utility function to programmatically add global methods, directives, mixins, and properties to Vue instances. It is specifically designed for use with Vue 2 applications, often employed in testing scenarios to mock or extend the global Vue constructor or instances derived from it using `Vue.extend()`. The current stable version is 2.0.1, but the package is no longer actively maintained, with its GitHub repository having been archived by the owner in 2017. Its release cadence was sporadic. A key differentiator was its ability to dynamically extend Vue's global capabilities without modifying the core `Vue` object directly if used with `Vue.extend()`, making it useful for isolated test environments. However, its design principles are largely incompatible with Vue 3's new application instance API, which moved away from a global Vue constructor pattern.

npm install vue-add-globals
INSTALL
IMPORT
SIG · VUE-ADD-GLOBALS
V
vue-add-globals
testingjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

addGlobals
import addGlobals from 'vue-add-globals'
import { addGlobals } from 'vue-add-globals'
The `addGlobals` function is a default export.
addGlobals (CommonJS)
const addGlobals = require('vue-add-globals')
While examples show ESM, CommonJS `require` is also typically supported for older Node.js environments and build setups where this package would have been relevant.

Demonstrates adding a global method and property to a Vue instance using `addGlobals` for testing or isolated environments, emphasizing its Vue 2 context.

import addGlobals from 'vue-add-globals' import { createApp } from 'vue' // NOTE: This utility is for Vue 2. The example below uses Vue 2 concepts. // For demonstration purposes, we'll simulate a Vue 2 context. // Simulate a Vue 2 like constructor for demonstration class MockVue { constructor() {} extend() { return class MockExtendedVue { constructor() {} $mount() { return this; } } } } // In a real Vue 2 app, you would import Vue directly: // import Vue from 'vue' // const freshVue = Vue.extend(); const freshVue = new MockVue().extend(); // Simulate Vue.extend() const $mockedMethod = () => ({ message: 'Hello from mock!' }) const mockedProp = 'Test Prop Value' addGlobals(freshVue, { $mockedMethod: $mockedMethod, mockedProp: mockedProp }) // Simulate a component using these globals const TestComponent = { template: '<div></div>', mounted() { console.log('Method result:', this.$mockedMethod()); console.log('Property value:', this.mockedProp); } }; // Simulate mounting the component const vm = new freshVue(TestComponent).$mount(); // Expected output in console: // Method result: { message: 'Hello from mock!' } // Property value: Test Prop Value
Debug
Known issues
breakingThis package is designed for Vue 2's global constructor API. It is incompatible with Vue 3, which uses an application instance API (`createApp`) and `app.config.globalProperties` for global registration. Attempting to use it with Vue 3 will not work as expected.
fix
For Vue 3, use `app.config.globalProperties` or `app.mixin` on the application instance returned by `createApp()`.
affects: All versions, when used with Vue 3
deprecatedThe `vue-add-globals` package is no longer actively maintained. Its GitHub repository has been archived, indicating it will receive no further updates, bug fixes, or security patches. Users should consider alternatives or be aware of the risks of using abandoned software.
fix
Migrate to a different solution or consider the implications of using unmaintained software. For testing Vue 2, manually mock global properties if `Vue.extend()` is insufficient.
affects: >=2.0.1
gotchaModifying the global `Vue` constructor directly can lead to unintended side effects across multiple tests or components. The `README` recommends using `Vue.extend()` to create a fresh, isolated Vue constructor for modifications.
fix
Always apply `addGlobals` to a fresh instance created with `Vue.extend()` (e.g., `addGlobals(Vue.extend(), {...})`) rather than directly to the main `Vue` object, especially in test environments.
affects: All versions
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading '$someMethod') or 'this.$someMethod is not a function'
This typically occurs when `vue-add-globals` is used with a Vue 3 application, where the global properties API has changed, or if the `addGlobals` call was not applied to the correct Vue instance/constructor.
fix
Ensure you are using Vue 2. If using Vue 2, verify that `addGlobals` was called on the `Vue` constructor or a `Vue.extend()` instance *before* components that rely on these globals are created.
Error: Vue.config.silent is not a function / TypeError: Vue.config.warnHandler is not a function
This package is designed for Vue 2. Attempting to use it with Vue 3 may lead to errors when the internal `vue-add-globals` logic tries to access Vue 2-specific properties or methods on a Vue 3 instance.
fix
This package is incompatible with Vue 3. Use Vue 3's native `app.config.globalProperties` or `app.mixin` for global functionality.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
vuerequiredThis package is designed to operate on a Vue instance or constructor, primarily Vue 2. It's usually a peer/dev dependency for projects using this utility.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
vue-add-globals — npm install vue-add-globals · libregistry