SupremeTechnopriest / socket.io-mock

Mock for socket.io
MIT License
38 stars 11 forks source link

TypeError: socket_io_mock_1.default is not a constructor #21

Open Mnigos opened 3 years ago

Mnigos commented 3 years ago

I tried to create a test but i got error with using socket.io-mock library. I'm using Typescript btw.

room.gateway.spec.ts

import { Test, TestingModule } from '@nestjs/testing'
import { RoomGateway } from './room.gateway'
import { Socket } from 'socket.io'
import SocketMock from 'socket.io-mock'

let socket: Socket

describe('RoomGateway', () => {
  let roomGateway: RoomGateway

  beforeEach(async () => {
    const RoomModule: TestingModule = await Test.createTestingModule({
      providers: [RoomGateway],
    }).compile()

    socket = SocketMock()
    roomGateway = RoomModule.get<RoomGateway>(RoomGateway)
  })

  it('Should be defined', () => {
    expect(roomGateway).toBeDefined()
  })

  it('Should return message that we provide', async () => {
    expect(roomGateway.handleMessage(socket, 'Hello World')).toEqual({
      event: 'message',
      data: 'Hello World',
    })
  })
})
gtestault commented 2 years ago

try import * as MockedSocket from "socket.io-mock