Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
Vue Unit Test: provide injection variable not found

I have a vue file having inject which also has a unit test file. When I run the test: utils I'm getting the following warning. What is the proper way of using provide while mounting the component in test file? I tried to do it the same way as shown in vue test docuentation but still something is not right.

export default {
  name: "Navbar",
  inject: ["emitter"],
  props: {
  ishome: {
      default: true,
      type: Boolean,
    },
  },
  data() {
    return {
      isFeedback: false,
    };
  },

  mounted() {
    this.emitter.on("openFeedback", () => {
      this.isFeedback = true;
    });
    this.emitter.on("closeFeedback", () => {
      this.isFeedback = false;
    });
  },
}
import { mount } from "@vue/test-utils";
import Navbar from "../components/Navbar.vue";
import mitt from "mitt";

describe("Mounted App isHome true", () => {
  try {
    const emit = mitt();
    const wrapper = mount(Navbar, {
      provide: {
        emitter() {
          return emit;
        },
      },
      props: {
        isHome: true,
      },
    });
  } catch (error) {
    expect(error).toBe("");
  }
console.warn node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6533
      [Vue warn]: injection "emitter" not found. 
        at <Navbar isHome=true ref="VTU_COMPONENT" > 
        at <VTUROOT>
    console.warn node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6533
      [Vue warn]: Unhandled error during execution of mounted hook 
        at <Navbar isHome=true ref="VTU_COMPONENT" > 
        at <VTUROOT>
    console.warn node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6533
      [Vue warn]: injection "emitter" not found. 
        at <Navbar isHome=false ref="VTU_COMPONENT" > 
        at <VTUROOT>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!