-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to do Vue.use(CompositionAPI) in tests? #5
Comments
Huh, there is a Vue exported, so I'm trying: import Vue from "vue";
import CompositionApi from "@vue/composition-api";
import { Vue as VueDemiVue } from 'vue-demi';
Vue.use(CompositionApi);
VueDemiVue.use(CompositionApi); But I get:
|
Thanks, I will have a look on that. And you don't have to install VCA I think. vue-demi should already do that for you. Meanwhile, If you want to install other plugins, the best way to do might be: import { createApp } from 'vue-demi'
const app = createApp()
app.use(xxxx) as |
I'm doing now Then I'm creating a wrapper component in which I want to test the utility functions export function createComponentStub(
name: string,
setup = (props, context) => { }
) {
const stubAttr = `data-test-${name}-stub`;
return Vue.defineComponent({
name,
setup,
render(el) {
return el("div", {
attrs: {
[stubAttr]: true,
},
});
},
});
} When I render this component I pass localVue from render(component, {
localVue: Vue as any
}); Still it seems that https://github.com/antfu/vue-demi/blob/master/lib/v2/index.esm.js#L5 |
But
|
If I uninstall VCA completely I'm getting:
|
Yes. From v0.3.x, |
And I think you should use import { defineComponent } from "vue-demi" instead of import Vue from "vue-demi" |
Yes, that looks strange: import VueCompositionApi from '@vue/composition-api';
import { Vue, isVue2, createApp, defineComponent } from 'vue-demi';
import { tracked, calculated } from '.';
if (isVue2) {
console.log('Vue 2', ((Vue as unknown) as Record<string, unknown>)['__composition_api_installed__']); // Vue 2 undefined ?!
Vue.use(VueCompositionApi);
console.log('Vue 2', ((Vue as unknown) as Record<string, unknown>)['__composition_api_installed__']); // Vue 2 true
} |
@Devoter What is the bundler you are using? Can you share a reproduce repo? Thanks. |
@antfu Sorry, I cannot share a repo for now. I use bili for building and ts-jest for testing. I'll try to prepare it for you later. |
Minimal repro: https://github.com/MartinMalinda/vue-tiny-emitter |
@MartinMalinda Sorry for the delay but I just pull done your repo and it seems to work for me |
I have to confirm, everything works fine with the lastest version. I don't know why. |
Hey, first of all great library it's something that's been much needed 👍 so thanks a bunch
I tried to use it in https://github.com/MartinMalinda/vue-concurrency and I hit a blocker that it breaks my test suite.
I have a quick setup file that is being run before every test:
https://github.com/MartinMalinda/vue-concurrency/blob/master/test-utils/vue-setup.ts
This worked fine before but it doesn't do the trick now when I import from
vue-demi
. I guess I do.use
on wrongVue
. Perhaps there needs to beimport { Vue } from 'vue-demi';
solely for testing purposes?The text was updated successfully, but these errors were encountered: