3

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.

1 Answer 1

4

Put all reactive properties inside __reactiveInject__. For example:

const wrapper = mount(Component, {
  localVue,
  provide: {
    __reactiveInject__: {
      foo: "bar"
    },
  },
});
Sign up to request clarification or add additional context in comments.

3 Comments

It does remove the warning but it doesn't pass the value to the Component. The value in this case foo is always undefined.
@ShamimHossain Interesting, it passes the value just fine for me... Try updating your packages or there may be a problem somewhere else in your project.
Thank you so much! I was looking for this for ages. How did you find out about this? I can't find any docs showing this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.