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