如何在Vue-test-utils上测试vue-property-decorator的@InjectReactive()?
我不确定在安装组件时如何提供注射反应性数据。我不需要确切的解决方案,只是一个提示将不胜感激。
这是我的父组件:
@Component
export default class Preferences extends Vue {
@ProvideReactive() serviceLevels: CarrierFilterType[] = [];
// more code here...
这是我的孩子组件:
@Component
export default class CarrierFilters {
@InjectReactive() readonly serviceLevels!: CarrierFilterType[];
// more code here...
这是我的测试文件:
// other imports are here...
import { supportedServiceLevels } from '../../constant';
// initial setup code here...
describe('Settings > Preferences > Content > CarrierFilters.vue', () => {
beforeEach(() => {
options = {
localVue,
i18n,
store,
router,
vuetify: new Vuetify(),
provide: { // I am not sure how to provide the inject-reactive data here...?
serviceLevels: [...supportedServiceLevels],
},
};
initWrapper = shallowMount(CarrierFilters, options);
});
// more code here...
当前,我在运行测试时会遇到以下控制台错误:
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Injection "__reactiveInject__" not found
found in
---> <CarrierFilters>
<Root>
顺便说一下,上面的代码正在使用@inject < /代码>,但不使用
@InjectReactive
。我已经看到了他们的源代码,似乎我必须以某种方式提供此密钥__ reactiveInject __
。
I am not sure how to provide the inject-reactive data when I mount the component. I don't need the exact solution, just a hint would be much appreciated.
Here is my parent component:
@Component
export default class Preferences extends Vue {
@ProvideReactive() serviceLevels: CarrierFilterType[] = [];
// more code here...
Here is my child component:
@Component
export default class CarrierFilters {
@InjectReactive() readonly serviceLevels!: CarrierFilterType[];
// more code here...
Here is my test file:
// other imports are here...
import { supportedServiceLevels } from '../../constant';
// initial setup code here...
describe('Settings > Preferences > Content > CarrierFilters.vue', () => {
beforeEach(() => {
options = {
localVue,
i18n,
store,
router,
vuetify: new Vuetify(),
provide: { // I am not sure how to provide the inject-reactive data here...?
serviceLevels: [...supportedServiceLevels],
},
};
initWrapper = shallowMount(CarrierFilters, options);
});
// more code here...
Currently, I am getting the below console error when I run the test:
console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Injection "__reactiveInject__" not found
found in
---> <CarrierFilters>
<Root>
By the way, the above code is working with the @Inject
but not with the @InjectReactive
. I have seen their source code, seems like I have to provide this key __reactiveInject__
somehow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将所有反应性属性放入
__ reactiveInject __
中。例如:Put all reactive properties inside
__reactiveInject__
. For example: