Skip to content

kimjoar/expect-to-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

expect-to-core

Core assertions for expect-to.

Installation

npm install --save-dev expect-to-core

These are included by default in expect-to, e.g.

import expect, { be, deepEqual } from 'expect-to'

Assertions

  • be — does a === check

    expect('test').to(be('test'));
  • deepEqual — does a deeply equal check using deep-eql

    expect({ foo: 'bar' }).to(deepEqual({ foo: 'bar' }));
  • not

    expect('test').to(not(be('testing')));
  • beTruthy

    expect('test').to(beTruthy);
    expect(null).to(not(beTruthy));
  • beFalsy

    expect('').to(beFalsy);
    expect('foo').to(not(beFalsy));
  • exist (i.e. neither null nor undefined)

    expect('test').to(exist);
    expect(null).to(not(exist));
  • beEmpty

    expect([]).to(beEmpty);
  • contain

    expect([1,2,3]).to(contain(2));
  • beInstanceOf

    expect(new Date()).to(beInstanceOf(Date));
  • beType

    expect(true).to(beType('boolean'));
    expect('foo').to(beType('string'));
  • match

    expect('TeSt').to(match(/test/i));
  • throwError

    expect(() => {
      throw new Error()
    }).to(throwError()),
    
    expect(() => {
      throw new Error()
    }).to(throwError(Error)),
    
    expect(() => {
      throw new Error('foo')
    }).to(throwError(Error, 'foo')),
    
    expect(() => {
      throw new Error('foo')
    }).to(throwError('foo')),
    
    expect(() => {
      throw new Error('foo')
    }).to(throwError(/foo/)),

About

Core assertions for `expect-to`

Resources

License

Stars

Watchers

Forks

Packages

No packages published