1.1.0 • Published 4 years ago

jest-to-be-typed v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

🎉 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

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago