No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Unit testing: mocking $q gives an error

    Help
    1
    1
    386
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • alexzehn
      alexzehn last edited by

      Hello,

      I am creating unit tests for my Quasar app via the Jest app extension, and I managed to mock global objects with the exception of $q. Here is my code:

      const wrapper = mount(NewPassword, {
        localVue,
        mocks: {
            $router: {
                push: jest.fn()
            },
            $q: {
                notify: jest.fn()
             },
            $root: {}
        }
      });
      

      When I run the tests I get the following error:

      ● NewPassword.vue › encountered a declaration exception

      TypeError: Cannot read property 'isActive' of undefined
      
        22 |   localVue.use(Quasar, { components }); // , lang: langEn
        23 | 
      > 24 |   const wrapper = mount(NewPassword, {
           |                   ^
        25 |     localVue,
        26 |     propsData: {
        27 |       showButton: false
      

      The error output is long, but I figured this is probably the most important part. If I comment out the $q part all my tests pass, so the problem is with the $q mock. I even tried the empty $q: {} mock statement, same error.

      Please help me she light on this problem.

      Thank you,
      Alex Z.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post