How to use jest-websocket-mock - 2 common examples

To help you get started, we’ve selected a few jest-websocket-mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github systemaccounting / mxfactorial / react / src / hooks / __tests__ / useNotifications.js View on Github external
import React from 'react'
import { mount } from 'enzyme'
import WS from 'jest-websocket-mock'
import useNotifications from '../useNotifications'

const server = new WS(
  process.env.REACT_APP_WSS_CLIENT_URL || 'wss://localhost:8080'
)
const mockNotifications = {
  pending: [
    {
      account: 'JoeSmith',
      human_timestamp: 'Mon, 18 Nov 2019 20:29:41 GMT',
      message:
        '[{"id":655,"name":"bread","price":"2","quantity":"2","author":"JoeSmith","creditor":"Person2","debitor":"JoeSmith","transaction_id":"25c1f950-0a42-11ea-b29c-59cf1afe88ac","debitor_approval_time":"2019-11-18 20:29:40.583 +00:00","unit_of_measurement":null,"units_measured":null,"rule_instance_id":null,"expiration_time":null,"debitor_profile_latlng":null,"creditor_profile_latlng":null,"debitor_transaction_latlng":null,"creditor_transaction_latlng":null,"creditor_approval_time":null,"debitor_device":null,"creditor_device":null,"debit_approver":null,"credit_approver":null,"creditor_rejection_time":null,"debitor_rejection_time":null,"createdAt":"2019-11-18T20:29:40.800Z"},{"id":656,"name":"9% state sales tax","price":"0.360","quantity":"1","author":"JoeSmith","creditor":"StateOfCalifornia","debitor":"JoeSmith","transaction_id":"25c1f950-0a42-11ea-b29c-59cf1afe88ac","rule_instance_id":"8f93fd20-e60b-11e9-a7a9-2b4645cb9b8d","debitor_approval_time":"2019-11-18 20:29:40.583 +00:00","unit_of_measurement":null,"units_measured":null,"expiration_time":null,"debitor_profile_latlng":null,"creditor_profile_latlng":null,"debitor_transaction_latlng":null,"creditor_transaction_latlng":null,"creditor_approval_time":null,"debitor_device":null,"creditor_device":null,"debit_approver":null,"credit_approver":null,"creditor_rejection_time":null,"debitor_rejection_time":null,"createdAt":"2019-11-18T20:29:40.801Z"}]',
      timestamp: 1574108981171521,
      uuid: '261c0032-0a42-11ea-a6e1-4380e87bdc44'
    },
    {
      account: 'JoeSmith',
      human_timestamp: 'Mon, 18 Nov 2019 20:27:45 GMT',
      message:
github pikax / vue-composable / packages / web / __tests__ / misc / webSocket.spec.ts View on Github external
beforeEach(() => {
    server = new WS(FAKE_URL);
    warnSpy.mockReset();
  });

jest-websocket-mock

Mock websockets and assert complex websocket interactions with Jest

MIT
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis

Popular jest-websocket-mock functions