How can I add my own matchers to Jasmine?


#1

The Jasmine 1.3 docs have a link to a wiki page about creating custom matchers, but the instructions do not work for me. Specifically, the jasmine.addMatchers() API that they use in the example does not seem to exist in the version of Jasmine bundled with Atom.


#2

I feel like Atom has some sort of hacked version of Jasmine. Is there a good place to look to see how it has been modified. It’s really frustrating because it basically means the Jasmine docs can’t be trusted. setTimeout() not working is another example of this. Similarly, waitsForPromise is nowhere to be found in the Jasmine 1.3 docs. Everything I have had to do related to async is pretty gross.


#3

Atom use jasmine-focused a fork of jasmine 1.3 that introduce focused tests (using f prefixed methods).

I believe the issue you have with matchers is due to the fact that the wiki page you are referring to is for the 2.0 version of jasmine and not for 1.3.x.

With 1.3 you create matchers like this:

  beforeEach ->
      @addMatchers
        toBeFoo: ->
          @message = -> "Expect #{@actual} to be foo"
          @actual is 'foo'

    it 'use custom matchers', -> expect('bar').toBeFoo()

#4

@abe, thanks. That explains a lot! :smile: