{"size": 1144, "ext": "js", "max_stars_repo_path": "test/unit/isSocketConnected.test.js", "max_stars_repo_name": "CaoMeiYouRen/node-cq-websocket", "max_stars_repo_stars_event_min_datetime": "2017-11-27T04:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T02:10:43.000Z", "max_issues_repo_path": "test/unit/isSocketConnected.test.js", "max_issues_repo_name": "CaoMeiYouRen/node-cq-websocket", "max_issues_repo_issues_event_min_datetime": "2017-11-27T07:48:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-23T06:12:30.000Z", "max_forks_repo_path": "test/unit/isSocketConnected.test.js", "max_forks_repo_name": "im20A0/node-cq-websocket", "max_forks_repo_forks_event_min_datetime": "2018-07-01T20:23:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T09:34:00.000Z"}
{"max_stars_count": 98, "max_issues_count": 87, "max_forks_count": 19, "avg_line_length": 23.3469387755, "max_line_length": 99, "alphanum_fraction": 0.6267482517}
// stuffs of stubbing
const { spy } = require('sinon')

const test = require('ava').default
const { CQWebSocketAPI: { CQWebSocket, WebSocketType } } = require('../fixture/connect-success')()

test.cb('#isSockConnected(wsType=/event)', function (t) {
  t.plan(2)

  const bot = new CQWebSocket()
  bot
    .on('socket.connect', function () {
      t.true(bot.isSockConnected(WebSocketType.EVENT))
      t.end()
    })
    .connect(WebSocketType.EVENT)

  t.false(bot.isSockConnected(WebSocketType.EVENT))
})

test.cb('#isSockConnected(wsType=/api)', function (t) {
  t.plan(2)

  const bot = new CQWebSocket()
  bot
    .on('socket.connect', function () {
      t.true(bot.isSockConnected(WebSocketType.API))
      t.end()
    })
    .connect(WebSocketType.API)

  t.false(bot.isSockConnected(WebSocketType.API))
})

test('#isSockConnected(): should have thrown', function (t) {
  t.plan(2)

  const bot = new CQWebSocket()
  spy(bot, 'isSockConnected')

  let res
  try {
    res = bot.isSockConnected()
  } catch (e) { }

  t.true(bot.isSockConnected.threw())
  t.is(typeof res, 'undefined')
})
