Vladimir Gordienko Vladimir Gordienko - 4 months ago 45x
AngularJS Question

Jasmine - any boolean (jasmine.any(Boolean))

I write unit tests for angular using karma, jasmine. Try to write:


but got:

Expected true to equal <jasmine.any(function Boolean() { [native code] })>.

mm.. maybe i do something wrong) or is it another way to write test for value in that case:

if (true or false) - passed, if any other - fail


I think what you need is a custom Matcher something like this:

toBeBoolean : function () {
  return {
    compare : function (actual, expected) {
      return {
        pass : (typeof expected === 'boolean'),
        message : 'Expected ' + actual + ' is not boolean'

How to create a Custom Matcher