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

252
Views
Jest Vuex TypeError: Cannot read properties of undefined (reading 'state')

I am using Quasar, vue and vuex. I have created a layout and would like to use jest to unit test. I have been copying bits of my layout code and running test as I go along.

This is my spec code

    import MainLayout from "../../../src/layouts/test";
    import { mountFactory } from "@quasar/quasar-app-extension-testing-unit-jest";
    import { QLayout, QHeader, QToolbar, QBtn, QToolbarTitle, QImg } from "quasar";
    
    const factory = mountFactory(MainLayout, {
      mount: { type: "full" },
      quasar: {
        components: { QLayout, QHeader, QToolbar, QBtn, QToolbarTitle, QImg },
      },
    });
    
    describe("test", () => {
      it("Show leftdrawer if leftDrawer is true", async () => {
        const wrapper = factory(MainLayout);
        await wrapper.vm.$nextTick();
        expect(wrapper.findComponent("button").isVisible()).toBe(true);
      });
    });

When I add this part in my MainLayout.vue 

<div v-if="!isAuthenticated">
      <q-btn
        @click="goTo('signin')"
        outline
        roundeded
        label="sign in"
        name="signin"
        class="q-mr-sm"
      >

And This part

computed: {
  ...mapState("member", {
  isAuthenticated: (state: MemberState) => state.isAuthenticated,
 })

},

I get this error when testing TypeError: Cannot read properties of undefined (reading 'state')

...mapState("member", {
isAuthenticated: (state: MemberState) => state.isAuthenticated,
})

How do I set up my spec file so that it reads in isAuthenticated from state in store.

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!