Socket
Book a DemoInstallSign in
Socket

jest-with-context

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

jest-with-context

```typescript // your.spec.ts import { createContext } from 'jest-with-context';

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

Usage, beautiful with prettier

// your.spec.ts
import { createContext } from 'jest-with-context';

const withContext = createContext({ foo: 0, whatever: 1 });

// just a describe wrapper, YourContext & { test }
withContext('test a api called whatever', ({ test, foo }) => {
  test('foo', ({ whatever }) => {
    expect(foo).toBe(0);
    expect(whatever).toBe(1);
  });
});

Usage, weird with prettier

// your.spec.ts
import { withContext } from '../src';

// just a describe wrapper, YourContext & { test }
withContext(
  'test a api called whatever',
  { foo: 0, whatever: 1 },
  ({ test, foo }) => {
    test('foo', ({ whatever }) => {
      expect(foo).toBe(0);
      expect(whatever).toBe(1);
    });
  }
);

Lifecycle

import { withContext } from '../src';

withContext('after each', { foo: 0 }, ({ test, afterEach }) => {
  let fooInternal = 0;
  afterEach(() => {
    fooInternal++;
    return { foo: fooInternal };
  });
  test('foo 0', ({ foo }) => {
    expect(foo).toBe(0);
  });
  test('foo 1', ({ foo }) => {
    expect(foo).toBe(1);
  });
});

// if you know what you're doing
withContext<{ foo: number }>(
  'before each without context',
  ({ test, beforeEach }) => {
    beforeEach((state = { foo: 0 }) => {
      return { foo: state.foo + 1 };
    });
    test('foo 1', ({ foo }) => {
      expect(foo).toBe(1);
    });
    test('foo 2', ({ foo }) => {
      expect(foo).toBe(2);
    });
  }
);

FAQs

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.