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

jest-plugin-context

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-plugin-context

Adds context as an alternative to describe to jest.

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
decreased by-7.03%
Maintainers
1
Weekly downloads
 
Created
Source

jest-plugin-context

npm npm npm

Adds context as an alternative to describe for jest.

Getting Started

Install jest-plugin-context using yarn:

yarn add --dev jest-plugin-context

Motivation

RSpec took the ruby world by storm with its declarative method of TDD. In RSpec, describe it used to wrap a set of tests against one functionality while context is to wrap a set of tests against one functionality under the same state.

The difference being you should only describe to test the User model and specifically describe the #name method. However, testing different states of the #name method should use different context. You can view an example of this below.

Usage

If you want, you can import context from jest-plugin-context at the top of every test:

import context from 'jest-plugin-context';

If you want to install context as a global, you can modify the jest section of your package.json to include:

"jest": {
  "setupFiles": [
    "jest-plugin-context/setup"
  ]
}

Example

Here's an example test that uses context:

describe('User', () => {

  describe('#name', () => {
    set('firstName', () => 'Harry');
    set('lastName', () => 'Potter');
    set('user', () => new User({firstName, lastName}));

    context('with blank first name', () => {
      set('firstName', () => null);

      it('should return only the last name', () => {
        expect(user.name).toEqual('Potter');
      });
    });

    context('with blank last name', () => {
      set('lastName', () => null);

      it('should return only the first name', () => {
        expect(user.name).toEqual('Harry');
      });
    });
  });
});

Keywords

FAQs

Package last updated on 21 Aug 2017

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