chai-asserttype

a chai plugin for type assertions, support typescript

Installation

npm install chai chai-asserttype-extra

install as chai plug-in

const ChaiPluginAssertType = require('chai-asserttype-extra');
import ChaiPluginAssertType = require('chai-asserttype-extra');
import ChaiPluginAssertType from 'chai-asserttype-extra';
import { ChaiPlugin as ChaiPluginAssertType } from 'chai-asserttype-extra';

choose one of ur fav way

when use .install will try make current chai support to new method in typescript, make without use @ts-ignore

const chai = ChaiPluginAssertType.install();
const chai = ChaiPluginAssertType.install(require('chai'));
const chai = require('chai-asserttype-extra').install()
const chai = require('chai');
chai.use(ChaiPluginAssertType);
const chai = require('chai');
chai.use(ChaiPluginAssertType);

Usage

this usage copy from GaneshSPatil/chai-asserttype

support both of .xxx() and .xxx

ChaiPluginAssertType.list()

console.log(ChaiPluginAssertType.list());
/*
[ 'array',
  'boolean',
  'date',
  'float',
  'function',
  'integer',
  'null',
  'number',
  'object',
  'regexp',
  'string',
  'undefined' ]
*/

Number

Asserts that type of actual is Number.

expect(1).to.be.number();
expect(0).to.be.number();
expect(-1).to.be.number();
expect(63465789908753).to.be.number();
expect(27.11).to.be.number();

expect(1).to.be.number;
expect(0).to.be.number;
expect(-1).to.be.number;
expect(63465789908753).to.be.number;
expect(27.11).to.be.number;

integer

expect(27).to.be.integer();
expect(27).to.be.integer;

float

expect(27.11).to.be.float();
expect(27.11).to.be.float;

String

Asserts that type of actual is String.

expect('').to.be.string();
expect('foobar').to.be.string();

Boolean

Asserts that type of actual is Boolean.

expect(true).to.be.boolean();
expect(false).to.be.boolean();

Object

Asserts that type of actual is Object.

expect({}).to.be.object();

Array

Asserts that type of actual is Array.

expect([]).to.be.array();
expect([1, 2, 3]).to.be.array();

Date

Asserts that type of actual is date.

expect(new Date()).to.be.date();

Function

Asserts that type of actual is Function.

expect(() => true).to.be.function();