0.2.3 • Published 6 years ago

jasmine-extra-matchers v0.2.3

Weekly downloads
8
License
MIT
Repository
github
Last release
6 years ago

Jasmine Extra Matchers

Build Status Coverage Status Code Climate dependencies Status devDependencies Status peerDependencies Status Dependency Status Downloads

A set of Jasmine 2.x matchers

Table of contents

Installation and usage

Bower

bower install jasmine-extra-matchers
<script src="/bower_components/jasmine-extra-matchers/dist/jasmine-extra-matchers.js"></script>
it('should be a Backbone.Model', function() {
    expect(value).toBeInstanceOf(Backbone.Model)
});

NPM

npm install jasmine-extra-matchers --save-dev
require('jasmine-extra-matchers');

it('should be infinity', function() {
  expect(value).toBeInfinity()
});

Matchers

toBeInstanceOf

Checks whether a value is the instance of type

expect(value).toBeInstanceOf(Backbone.Model)
expect(value).not.toBeInstanceOf(Backbone.Model)

toBeInfinity

Checks whether a value is infinity

expect(Infinity).toBeInfinity()
expect(0).not.toBeInfinity()

hasOwnProperty

Checks whether a value has own property

expect(value).hasOwnProperty('type')
expect(value).not.hasOwnProperty('type')

toBeEven

Checks whether the value is an even number

expect(2).toBeEven()
expect(3).not.toBeEven()

toBeOdd

Checks whether the value is an odd number

expect(3).toBeOdd()
expect(2).not.toBeOdd()

toBeNumeric

Checks whether the value contains a numeric value, regardless of its type. It can be a string containing a numeric value, exponential notation, a Number object, etc.

expect('14').toBeNumeric()
expect('fourteen').not.toBeNumeric()

toBeInteger

Checks whether the value is a numeric integer. A numeric value can be a string containing a number, a Number object, etc.

expect(18).toBeInteger()
expect('18').toBeInteger()
expect(2.5).not.toBeInteger()
expect(-1).toBeInteger()

toBeFloat

Checks whether the value is a "float"

expect(1.1).toBeFloat()
expect(1).not.toBeFloat()
expect(1.0).not.toBeFloat()
expect('2.15').toBeFloat()

toBePositive

Checks whether the value is a positive number

expect(21).toBePositive()
expect(-1).not.toBePositive()

toBeNegative

Checks whether the value is a negative number

expect(-2).toBeNegative()
expect(5).not.toBeNegative()