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

mockyeah

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockyeah

A powerful service mocking, recording, and playback utility.

  • 0.16.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
90
increased by13.92%
Maintainers
1
Weekly downloads
 
Created
Source

mockyeah Build Status

"A powerful service mocking, recording, and playback utility."

Testing is difficult when you don't have control of your data. mockyeah puts you in complete control, enabling you to implement real mock web services with ease. Real mock services means you have control of response payloads, HTTP Status Codes, response latency, and more.

Have a requirement to implement specific behavior when a service is slow to respond or a server returns an unexpected status code? No problem! mockyeah makes developing for such requirements easy.

Install

$ npm install mockyeah --save-dev

Usage

API

CLI

Introductory tutorial

  1. Create an example project and initialized with NPM

    $ mkdir example-app && cd example-app
    $ npm init # all defaults will be fine
    
  2. Install mockyeah

    $ npm install mockyeah --save-dev
    
  3. Create script file and add the source below

    $ touch index.js
    
    const mockyeah = require('mockyeah');
    
    mockyeah.get('/hello-world', { text: 'Hello World' });
    
  4. Run the script file with Node

    $ node index.js
    
  5. Open http://localhost:4001/hello-world

  6. Profit. You should see "Hello World" returned from your mock server.

Testing with mockyeah

const request = require('supertest')('http://localhost:4001');
const mockyeah = require('mockyeah');

describe('Wondrous service', () => {
  // remove service mocks after each test
  afterEach(() => mockyeah.reset());

  // stop mockyeah server
  after(() => mockyeah.close());

  it('should create a mock service that returns an internal error', (done) => {
    // create failing service mock
    mockyeah.get('/wondrous', { status: 500 });

    // assert service mock is working
    request
      .get('/wondrous')
      .expect(500, done);
  });

  it('should create a mock service that returns JSON', (done) => {
    // create service mock that returns json data
    mockyeah.get('/wondrous', { json: { foo: 'bar' } });

    // assert service mock is working
    request
      .get('/wondrous')
      .expect(200, { foo: 'bar' }, done);
  });

  it('should verify a mock service expectation', (done) => {
    // create service mock with expectation
    const expectation = mockyeah
      .get('/wondrous', { text: 'it worked' })
      .expect()
      .params({
        foo: 'bar'
      })
      .once();

    // invoke request and verify expectation
    request
      .get('/wondrous?foo=bar')
      .expect(200, 'it worked')
      .then(() => {
        expectation.verify();
        done();
      });
  });
});

Keywords

FAQs

Package last updated on 25 Jan 2018

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