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 - How to mock $q.platform.is.[...]?

    Help
    jest platform test testing vue-test-utils
    1
    2
    478
    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.
    • G
      geddy last edited by geddy

      Hello,

      I am creating unit tests for my Quasar app via the Jest app extension but I am struggling to work out how I can simulate the user being on a desktop/mobile via $q.platform.is.desktop. As I am running the tests on a desktop computer, $q.platform.is.desktop always returns true, but I want to modify this to return false - how can this be done?

      How can I mock $q.platform so that I am able to expand on my tests cases to include these scenarios as my code is conditional and acts based on the users platform.

      Thank you,
      geddy

      1 Reply Last reply Reply Quote 0
      • G
        geddy last edited by

        Fixed my own issue.

        I created a computed property - isDesktop() - that returns “this.$q.platform.is.desktop”. Then within my test file, I dynamically updated the computed property that then allowed me to test the functionality.

        I defined a factory function that is then called in beforeEach().

        const factory = (computed = { }) => {
        return shallowMount(App, {
        computed
        });
        };

        beforeEach(() => {
        wrapper = factory();
        });

        For the test that requires the updated computer property, I then called the factory function and set the computed property value.

        it(‘my amazing test’, () => {
        wrapper = factory({
        isDesktop: () => false
        });

        expect(addYourAssertionHere)
        })

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