Skip to content

Commit

Permalink
Show array in assertion message (instead of last element).
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Jan 7, 2013
1 parent 2415326 commit 092f372
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/chai-things.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@
}
}
}, this);

this._targetArray = targetArray;
}

// SomethingAssertion members
SomethingAssertion.prototype = {
// Change the assertion message to an array viewpoint
assert: function (test, positive, negative, expected, actual) {
utils.flag(this, "object", this._targetArray);
Assertion.prototype.assert.call(this,
test,
positive.replace("#{this}", "an element of #{this}"),
Expand Down
2 changes: 1 addition & 1 deletion test/something.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ describe "include.something", ->

it "does not pass if an equal element does not exist", ->
(() -> [{ a: 1 }, { b: 2 }].should.include.something.that.deep.equals { c: 3 }).
should.throw("expected an element of { b: 2 } to deeply equal { c: 3 }")
should.throw("expected an element of [ { a: 1 }, { b: 2 } ] to deeply equal { c: 3 }")

0 comments on commit 092f372

Please sign in to comment.