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
    1. Home
    2. Ceriel
    C
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 1
    • Best 1
    • Groups 0

    Ceriel

    @Ceriel

    1
    Reputation
    1
    Profile views
    1
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Ceriel Follow

    Best posts made by Ceriel

    • How to unit test a bootfile with Jest?

      I would like to test axios response interceptors and routeguard, for which I have created boot files.

      How do I test these type of files in Jest? Since the logic lives in the export default callback.

      import {
        Notify
      } from 'quasar'
      
      import {
        i18n
      } from 'boot/i18n.js'
      import {
        axiosInstance
      } from 'boot/axios'
      
      export default ({
        router,
        store
      }) => {
        axiosInstance.interceptors.response.use(response => {
          return response
        }, error => {
          if (error.response.status === 401) {
            Notify.create({
              progress: true,
              message: i18n.t('response.status-code-401'),
              icon: 'error',
              color: 'white',
              textColor: 'primary'
            })
      
            setTimeout(() => {
              store.dispatch('auth/logout')
            }, 5000)
      
            return Promise.reject(error)
          }
          // TODO: Notify for other status codes
        })
      
        /**
         * Set route guard
         */
        router.beforeEach((to, from, next) => {
          const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
      
          if (requiresAuth) {
            store.dispatch('auth/fetchUser').then(() => {
              if (!store.getters['auth/isLoggedIn']) {
                next({
                  path: '/login',
                  query: {
                    redirect: to.fullPath
                  }
                })
              } else {
                next()
              }
            })
          } else {
            next()
          }
        })
      }
      
      
      
      posted in Help
      C
      Ceriel

    Latest posts made by Ceriel

    • How to unit test a bootfile with Jest?

      I would like to test axios response interceptors and routeguard, for which I have created boot files.

      How do I test these type of files in Jest? Since the logic lives in the export default callback.

      import {
        Notify
      } from 'quasar'
      
      import {
        i18n
      } from 'boot/i18n.js'
      import {
        axiosInstance
      } from 'boot/axios'
      
      export default ({
        router,
        store
      }) => {
        axiosInstance.interceptors.response.use(response => {
          return response
        }, error => {
          if (error.response.status === 401) {
            Notify.create({
              progress: true,
              message: i18n.t('response.status-code-401'),
              icon: 'error',
              color: 'white',
              textColor: 'primary'
            })
      
            setTimeout(() => {
              store.dispatch('auth/logout')
            }, 5000)
      
            return Promise.reject(error)
          }
          // TODO: Notify for other status codes
        })
      
        /**
         * Set route guard
         */
        router.beforeEach((to, from, next) => {
          const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
      
          if (requiresAuth) {
            store.dispatch('auth/fetchUser').then(() => {
              if (!store.getters['auth/isLoggedIn']) {
                next({
                  path: '/login',
                  query: {
                    redirect: to.fullPath
                  }
                })
              } else {
                next()
              }
            })
          } else {
            next()
          }
        })
      }
      
      
      
      posted in Help
      C
      Ceriel