spyfu-vue-factory

Unit testing factory for Vue components.
1,058 1
Install
npm install spyfu-vue-factory
Latest Version:0.7.4
Vue:2
License:MIT
Last Updated:Jan 2, 2020
Links: GitHub  ·  npm
Maintainer: scottbedard

spyfu-vue-factory

Build status Coverage Dev dependencies npm License

Installation

This utility creates factory functions for Vue components. To get started, install through NPM or Yarn.

# install through npm
$ npm install spyfu-vue-factory

# or with yarn
$ yarn add spyfu-vue-factory

Basic usage

To create a component factory, pass any child components, routes, and vuex modules to the factory function. All three of these properties are optional.

import { factory } from 'spyfu-vue-factory';

const mount = factory({
    components: {
        'child-component': childComponent,
    },
    modules: {
        exampleVuexModule,
    },
    routes: [
        exampleRoute,
    ],
});

Once you've made your factory, you may use it to instantiate Vue components.

const vm = mount({
    template: `<div>Hello from a test component</div>`,
});

Initial Vuex state may be supplied as the second argument. This state will be deeply merged with the default Vuex state.

const vm = mount({
    template: `<div>Hello from a test component</div>`,
}, {
    moduleNamespace: {
        key: 'new value',
    },
});

Stubbing named routes

Occasionally in tests that interact with vue-router, you'll see the following error.

[vue-router] Route with name 'whatever' does not exist

This is usually caused by trying to render a <router-link> component using a named route that your test factory does not know about. To remedy this, simply pass in the route name to the routes array.

const mount = factory({
    routes: [
        'whatever',
    ],
});

Using a custom Vue constructor

Optionally, the factory can work with a sub-classed Vue constructor. To do this, provide a Vue property in your factory options.

const mount = factory({
    Vue: Vue.extend(/* ... */),
});

License

MIT

Copyright (c) 2017-present, SpyFu

Related Packages

vuex-router-sync

Effortlessly keep vue-router and vuex store in sync.

4,091,575 2,487
vuexi

Vuex and Vue Router helper functions

642 5
web-killer

vue2 webcomponents

1,438
vue-fetch-route

This npm package provides various helper methods to ease the pain of fetching, s...

895 6
spyfu-vuex-helpers

Utility functions for Vuex.

2,459 9

Version History

Version Released Vue License
0.7.4 ^2.5.2 MIT
0.7.3 ^2.5.2 MIT
0.7.2 ^2.5.2 MIT
0.7.1 ^2.5.2 MIT
0.7.0 ^2.5.2 MIT