Jasmine 2.0.3 - custom matcher - toBeInteger
toBeInteger matcher
HTML
<script src="https://safjanowski.github.io/jasmine-jsfiddle-pack/pack/jasmine-2.0.3-concated.js"></script>
<link rel="stylesheet" href="https://safjanowski.github.io/jasmine-jsfiddle-pack/pack/jasmine.css">
JavaScript
describe('Custom matcher', function () {
beforeEach(function () {
jasmine.addMatchers({
toBeInteger: function toBeInteger() {
function compare(actual) {
var result = {};
result.pass = actual === ~~ (actual);
if (result.pass) {
result.message = 'Expected ' + actual + ' not to be an integer value';
} else {
result.message = 'Expected ' + ~~ (actual) + ' but got ' + actual;
}
return result;
}
return {
compare: compare
}
}
})
});
describe('toBeInteger mather', function () {
it('match proper integer value', function () {
expect(5).toBeInteger();
expect(0).toBeInteger();
});
it('test not mathcer', function () {
expect(5.2).not.toBeInteger();
});
});
});