# jest-context

> Adds context as an alternative to describe to jest.

Latest version **2.1.0** (published 2017-07-31) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install jest-context
pnpm add jest-context
yarn add jest-context
bun add jest-context
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2017-07-31 |
| First published | 2017-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mark Miyashita |
| Maintainers | negativetwelve |
| Keywords | context, jest, test |

## Links

- npm: https://www.npmjs.com/package/jest-context
- Repository: https://github.com/negativetwelve/jest-context
- Issues: https://github.com/negativetwelve/jest-context/issues
- npm.io page: https://npm.io/package/jest-context

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2017-07-31
- 2.0.0 — 2017-07-31
- 1.2.0 — 2017-07-27
- 1.1.0 — 2017-07-27
- 1.0.1 — 2017-07-27
- 1.0.0 — 2017-07-27

## README

# jest-context

[![npm](https://img.shields.io/npm/v/jest-context.svg)](https://www.npmjs.com/package/jest-context)
[![npm](https://img.shields.io/npm/dt/jest-context.svg)](https://www.npmjs.com/package/jest-context)
[![npm](https://img.shields.io/npm/l/jest-context.svg)](https://github.com/negativetwelve/jest-context/blob/master/LICENSE)
[![CircleCI branch](https://img.shields.io/circleci/project/github/negativetwelve/jest-context/master.svg)](https://circleci.com/gh/negativetwelve/jest-context)

Adds `context` as an alternative to `describe` for jest.

## Getting Started

Install `jest-context` using `yarn`:

```shell
yarn add --dev jest-context
```

## Motivation

[RSpec](http://rspec.info/) 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-context` at the top of every test:

```javascript
import context from 'jest-context';
```

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

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

## Example

Here's an example test that uses `context`:

```javascript
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');
      });
    });
  });
});
```

---
_Source: https://npm.io/package/jest-context · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
