A set of Jasmine 2.x matchers
bower install jasmine-extra-matchers
<script src="/bower_components/jasmine-extra-matchers/jasmine-extra-matchers.js"></script>
it('should be a Backbone.Model', function() {
expect(value).toBeInstanceOf(Backbone.Model)
});
npm install jasmine-extra-matchers --save-dev
require('jasmine-extra-matchers');
it('should be infinity', function() {
expect(value).toBeInfinity()
});
Use karma-jasmine-extra-matchers
Checks whether a value is the instance of type
expect(value).toBeInstanceOf(Backbone.Model)
expect(value).not.toBeInstanceOf(Backbone.Model)
Checks whether a value is infinity
expect(Infinity).toBeInfinity()
expect(0).not.toBeInfinity()
Checks whether a value has own property
expect(value).hasOwnProperty('type')
expect(value).not.hasOwnProperty('type')
Checks whether the value is an even number
expect(2).toBeEven()
expect(3).not.toBeEven()
Checks whether the value is an odd number
expect(3).toBeOdd()
expect(2).not.toBeOdd()
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()
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()
Checks whether the value is a "float"
expect(1.1).toBeFloat()
expect(1).not.toBeFloat()
expect(1.0).not.toBeFloat()
expect('2.15').toBeFloat()
Checks whether the value is a positive number
expect(21).toBePositive()
expect(-1).not.toBePositive()
Checks whether the value is a negative number
expect(-2).toBeNegative()
expect(5).not.toBeNegative()