1

When I trigger a function that requests API from $socket.client.emit I received client undefined after running npm run test:unit. I used 2 package from Vue when using socket-io here's my code from Vue main.js

import socket from 'vue-socket.io-extended'
import socketio from 'socket.io-client'

Vue.use(socket, socketio("http://ip_address:port), { store })

and here's my code from vue test utils

import Vue from 'vue'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
import Vuetify from 'vuetify'

import SocketIOExt from 'vue-socket.io-extended'
import SocketIO from 'socket.io-client'


import { createLocalVue, mount } from '@vue/test-utils'

import Login from '@/components/authentication/Login.vue'


import { store } from '@/store.js'


describe('Login.vue', () => {
  let wrapper
  const localVue = createLocalVue()
  
  const vuetify = new Vuetify()
  localVue.use(Vuetify)

  const router = new VueRouter()
  localVue.use(VueRouter)
  let $route

  localVue.use(Vuex)
  let $store

  beforeEach(() => {
    wrapper = mount(Login, {
      localVue,
      vuetify,
      router,
      store,

      mocks: {
        $route,
        $store
      }
    });
  });


  it('login a account', async () => {
    const data = {
      email: "[email protected]",
      password: 'admin1234'
    }
    
    
    let email = wrapper.get('#text-field-email')
    let password = wrapper.get('#text-field-password')
    let button = wrapper.get('#button-login')

    email.setValue(data.email)
    password.setValue(data.password)

    await button.vm.$emit('click')
  });
});

this is the picture of error I received enter image description here

Question: how can I introduce socket-io from vue test utils? What I am trying to achieve here is to mock

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.