Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ws-dependency-mock

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ws-dependency-mock

Library for mock web socket server.

  • 0.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

##ws-dependency-mock

Install

npm i ws-dependency-mock --save

Usage

Validations

import { IsInt, IsEmail, Min, IsNotEmpty, IsString, MinLength, MaxLength } from 'class-validator';

export class UserModel {
    @IsNotEmpty()
    @IsInt()
    @Min(1)
    id: number;

    @IsNotEmpty()
    @IsString()
    @MinLength(2)
    @MaxLength(255)
    first: string;

    @IsNotEmpty()
    @IsString()
    @MinLength(2)
    @MaxLength(255)
    last: string;

    @IsNotEmpty()
    @IsString()
    @IsEmail()
    email: number;
}

Contract


import { AbstractContract } from '../../../src/abstract-contract';
import { UserModel } from '../../../test/src/models/user.model';

export class UserContract extends AbstractContract {

    init(): void {
        this
            .add({
                validation: UserModel, // Check validation
                payload: {             // Your mocked payload
                    test: 'success',
                },
                repeat: 1,             // Count of repeat. Default: 1
                timeout: 500           // Timeout return mock payload. Default: 0
            });
    }
}

Contract registration
import { ContractInterface } from '../../src/interfaces/contract.interface';
import { ContractNotFoundException } from '../../src/exceptions/contract-not-found.exception';
import { UserContract } from '../../test/src/contracts/user.contract';

export class ContractFactory {
    create(key: string): ContractInterface {
        switch (key) {
            case 'user': return new UserContract();
            default: throw new ContractNotFoundException(key);
        }
    }
}


Run
const wsm = new WebSocketMock({
    host: 'localhost',
    port: 8080,
});

wsm.run(new ContractFactory());
Dependencies
  • ws
  • class-validatior

Enjoy!

FAQs

Package last updated on 31 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc