New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@shopify/jest-koa-mocks

Package Overview
Dependencies
Maintainers
9
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/jest-koa-mocks

## Installation

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
31K
increased by0.72%
Maintainers
9
Weekly downloads
 
Created
Source

@shopify/jest-koa-mocks

Installation

$ yarn add @shopify/jest-koa-mocks

Usage

createContext

This function allows you to create fully stubbable koa contexts for your tests. Using this you can test middleware without actually having to setup an app or http mocks in your tests.

  interface Options extends Dictionary<any> {
    url?: string;
    method?: RequestMethod;
    statusCode?: number;
    session?: Dictionary<any>;
    headers?: Dictionary<string>;
    [key: string]: any;
  }

  createContext(options: Options)

simple example

import SillyViewCounterMiddleware from '../silly-view-counter';
import {createMockContext} from '@shopify/jest-koa-mocks';

describe('silly-view-counter', () => {
  it('iterates and displays new ctx.state.views', async () => {
    const ctx = createMockContext({state: {views: 31}});

    await SillyViewCounterMiddleware(ctx);

    expect(ctx.state.views).toBe(32);
    expect(ctx.status).toBe(200);
    expect(ctx.body).toBe({view: 32});
  });
});

FAQs

Package last updated on 01 May 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