Is there a way to add a Jasmine matcher to the whole environment

Sure, you just call beforeEach() without any spec scoping at all, and add matchers there.

This would globally add a toBeOfType matcher.

beforeEach(function() {
  var matchers = {
    toBeOfType: function(typeString) {
      return typeof this.actual == typeString;
    }
  };

  this.addMatchers(matchers);
});

describe('Thing', function() {
  // matchers available here.
});

I’ve made a file named spec_helper.js full of things like custom matchers that I just need to load onto the page before I run the rest of the spec suite.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)