All files / tests/unit ComponentBuilder.js

79.17% Statements 19/24
33.33% Branches 1/3
80% Functions 8/10
79.17% Lines 19/24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69        19x         9x     13x           19x 19x 19x 19x 19x 19x       9x 9x       19x 19x                           19x 19x       19x   19x           19x       19x        
import { createLocalVue, mount, shallowMount } from '@vue/test-utils';
 
 
export function build(component) {
    return component.build();
}
 
class BaseComponent {
    get with() {
        return this;
    }
    get and() {
        return this;
    }
}
 
export class Component extends BaseComponent {
    constructor(vueComponent) {
        super();
        this._component = vueComponent;
        this._options = {};
        this._props = {};
        this._data = undefined;
        this.shallowMount();
    }
 
    mount() {
        this._mountFunction = mount;
        return this;
    }
 
    shallowMount() {
        this._mountFunction = shallowMount;
        return this;
    }
 
    data(data) {
        this._data = data;
        return this;
    }
 
    options(options) {
        Object.assign(this._options, options);
        return this;
    }
 
    props(props = {}) {
        Object.assign(this._props, props);
        return this;
    }
 
    build() {
        const localVue = createLocalVue();
 
        const buildComponent = this._mountFunction(this._component, {
            localVue,
            ...this._options,
            propsData: this._props,
        });
 
        Iif (this._data) {
            buildComponent.setData(this._data);
        }
 
        return buildComponent;
    }
}