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 Test a Quasar Dialog

    Framework
    dialog jest qdialog test vue-test-utils
    3
    4
    1230
    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.
    • Jezzta667
      Jezzta667 last edited by

      Hey guys,

      I would like to write a unit test to check that upon confirmation, a Quasar dialog will emit an event in it’s .then() function.

      Given that this would normally involve clicking the OK button, is there any way to easily accomplish this in a unit test?

      I am using Jest and Vue Test Utils.

      My test so far

      it('will emit signUp when the dialog is confirmed', () => {
          const wrapper = createWrapper()
      
          wrapper.vm.$q.dialog.call()
      
          // What's the best way to trigger the 'ok' event from here?
      
          expect(wrapper.emitted().signUp).toHaveLength(1)
        })
      

      Thanks a lot.

      1 Reply Last reply Reply Quote 0
      • Jezzta667
        Jezzta667 last edited by

        Just in case this helps anyone, it’s easy enough to simply replace the $q.dialog function with a mock function that returns a Promise.resolve().

        Be sure to handle the promise asynchronously

        import flushPromises from 'flush-promises'
        
        it('will emit signUp when the dialog is confirmed', async () => {
            const wrapper = createWrapper()
        
            wrapper.vm.$q.dialog = jest.fn(() => Promise.resolve())
        
        await flushPromises()
        
            expect(wrapper.emitted()).toHaveProperty('signUp)
          })
        
        1 Reply Last reply Reply Quote 0
        • G
          glory_sy last edited by

          could you please tell me how to test the opening and closing of the dialog ?

          1 Reply Last reply Reply Quote 1
          • D
            DavidGo last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • First post
              Last post