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

jest-to-be-typed

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-to-be-typed

type checking using jest

1.1.0
latest
Source
npm
Version published
Weekly downloads
10
Maintainers
1
Weekly downloads
 
Created
Source

🎉 Jest To Be Typed

version downloads MIT License PRs Welcome

Jest matcher that allows you to test the expected type of value.

🔧 Installation

With npm

npm i jest-to-be-typed

With yarn

yarn add jest-to-be-typed

📦 Setup

Jest >v24

Add jest-to-be-typed to your Jest setupFilesAfterEnv configuration. See for help

"jest": {
  "setupFilesAfterEnv": ["jest-to-be-typed"]
}

Jest <v23

"jest": {
  "setupTestFrameworkScriptFile": "jest-to-be-typed"
}

OR

Simply import toBeTyped

// *.test.js
import toBeTyped from 'jest-to-be-typed'

expect.extend(toBeTyped);

✏️ Usage

There are two kinds of modes.

Default mode:

Default mode checks typeof expected value.

  expect('').toBeTyped('string');
  expect({}).toBeTyped('object');
  expect(1).toBeTyped('number');
  expect(false).toBeTyped('boolean');
  expect(Symbol('foobar')).toBeTyped('symbol');
  expect(() => {}).toBeTyped('function');
  expect([]).toBeTyped('array');
  expect(/foobar/).toBeTyped('regexp');
  expect(new RegExp('foobar')).toBeTyped('regexp');
  expect(null).toBeTyped('null');
  expect(undefined).toBeTyped('undefined');
  expect(new Map()).toBeTyped('map');
  expect(new Set()).toBeTyped('set');
  expect(new Date()).toBeTyped('date');
  expect(Promise.resolve([])).resolves.toBeTyped('array');

Advanced mode:

Advanced mode is somelike typescript interface.

  const data = {
    name: 'eddie',
    age: 13,
    address: [],
    isMarried: false
  };
  const types = {
    name: 'string',
    age: 'number',
    address: 'array',
    isMarried: 'boolean'
  };
  expect(data).toBeTyped(types);

📄 License

MIT

💡 Reference

Inspired by jest-tobetype

Keywords

jest

FAQs

Package last updated on 07 Aug 2020

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