Skip to content

Comparison Insights!

Choose a tag to compare

@searls searls released this 19 Sep 21:24
· 71 commits to master since this release

This release drastically improves output of tests that use comparators in Then statements to determine if the test passes. Previously, the error message would simply say that the statement returned false, now it'll detect comparisons and evaluate both sides and print them out (so long as both sides are eval-able and don't result in ReferenceErrors).

Here's an example:

context "simple !== matcher", ->
  Given -> @a = -> 1
  Given -> @b = 3
  Then -> @a() == @b

This will produce output like this:

Then clause `this.a() === this.b` failed by returning false

This comparison was detected:
  this.a() === this.b
  1 === 3

Similarly, if the two sides had deep-equalled each other, jasmine-given can now warn you that you should be using the toEqual matcher:

context "simple !== matcher", ->
  Given -> @a = -> [1]
  Given -> @b = [1]
  Then -> @a() == @b

Which will advise:

Then clause `this.a() === this.b` failed by returning false

This comparison was detected:
  this.a() === this.b
  1 === 1

However, these items are deeply equal! Try an expectation like this instead:
  expect(this.a()).toEqual(this.b)

Neat!

Keep in mind that this will result in a bunch of less-than-helpful ReferenceErrors if your Then statements are comparing things that aren't reachable by this or by global scopes. If both sides result in a reference error, jasmine-given will (╯°□°)╯︵ ┻━┻ and just continue doing what it always has.