Vladimir Gordienko Vladimir Gordienko - 2 years ago 197
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download