There are plenty of documents that show how to add a matcher to a Jasmine spec (here, for example).
Has anyone found a way to add matchers to the whole environment; I'm wanting to create a set of useful matchers to be called by any and all tests, without copypasta all over my specs.
Currently working to reverse engineer the source, but would prefer a tried and true method, if one exists.
Edit: I didn't know it was an internal implementation that may be subjected to change. Use at your own risk.
Based on previous answers, I created the following setup for angular-cli. I also need an external module in my matcher (in this case moment.js)
Note In this example I added an equalityTester, but it should work with a customer matcher
Create a file
src/spec_helper.ts
with the following contents:Then, in
src/test.ts
import theinitSpecHelper()
function add execute it. I placed it before Angular's TestBed init, wich seems to work just fine.Here's one for jasmine 2.0+:
Note that this uses angular's
angular.equals
.Sure, you just call
beforeEach()
without any spec scoping at all, and add matchers there.This would globally add a
toBeOfType
matcher.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.