UNPKG

vue-composable-tester

Version:

Utility to test composition api functions for Vue.js

58 lines (57 loc) 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mount = void 0; function mount(composable, options = {}) { const version = require('vue').version || require('vue').default.version; return /^3\./.test(version) ? mountV3(composable, options) : mountV2(composable, options); } exports.mount = mount; function mountV2(composable, options) { const Vue = require('vue') || require('vue').default; const app = new Vue({ setup() { var _a; (_a = options.provider) === null || _a === void 0 ? void 0 : _a.call(options); const result = composable(); const wrapper = () => result; return { wrapper }; }, render() { }, }); app.$mount(); return { result: app.wrapper(), unmount: () => app.$destroy(), }; } function mountV3(composable, options) { const { createApp, h } = require('vue'); const App = { setup() { var _a; (_a = options.provider) === null || _a === void 0 ? void 0 : _a.call(options); }, render() { return h(Child, { ref: 'child', }); }, }; const Child = { setup() { const result = composable(); const wrapper = () => result; return { wrapper }; }, render() { }, }; const root = document.createElement('div'); const app = createApp(App); const vm = app.mount(root); return { result: vm.$refs.child.wrapper(), unmount: () => app.unmount(), }; }