Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 10, 2012
@jfirebaugh jfirebaugh Fix `'foo'.should.contain('bar')`
It takes some gymnastics to call `apply` on a Function
whose __proto__ has been hijacked.

Fixes #7.
5c53f25
@jfirebaugh jfirebaugh Getters never have arguments a5f8421
Showing with 15 additions and 8 deletions.
  1. +4 −2 chai-jquery.js
  2. +11 −6 test/chai-jquery-spec.js
View
6 chai-jquery.js
@@ -171,7 +171,7 @@
chai.Assertion.overwriteProperty('contain', function (_super) {
return function () {
- _super.apply(this, arguments);
+ _super.call(this);
var contain = function (text) {
var obj = flag(this, 'object');
if (obj instanceof jQuery) {
@@ -181,6 +181,8 @@
, 'expected #{this} not to contain #{exp}'
, text
);
+ } else {
+ Function.prototype.apply.call(_super.call(this), this, arguments);
}
};
contain.__proto__ = this;
@@ -190,7 +192,7 @@
chai.Assertion.overwriteProperty('have', function (_super) {
return function () {
- _super.apply(this, arguments);
+ _super.call(this);
var have = function (selector) {
var obj = flag(this, 'object');
if (obj instanceof jQuery) {
View
17 test/chai-jquery-spec.js
@@ -4,25 +4,25 @@ describe("jQuery assertions", function(){
chai.use(function (chai, utils) {
inspect = utils.inspect;
- chai.Assertion.prototype.fail = function (message) {
+ chai.Assertion.addMethod('fail', function (message) {
var obj = utils.flag(this, 'object');
new chai.Assertion(obj).is.a('function');
try {
obj();
- this.assert(false, 'expected #{this} to fail');
} catch (err) {
this.assert(
err instanceof chai.AssertionError
, 'expected #{this} to fail, but it threw ' + inspect(err));
this.assert(
err.message === message
- , 'expected #{this} to fail with ' + inspect(message) + ', but got ' + inspect(err.message))
+ , 'expected #{this} to fail with ' + inspect(message) + ', but got ' + inspect(err.message));
+ return;
}
- return this;
- };
+ this.assert(false, 'expected #{this} to fail');
+ });
});
describe("attr", function(){
@@ -512,8 +512,13 @@ describe("jQuery assertions", function(){
describe("contain", function(){
it("preserves existing behavior on non-jQuery objects", function(){
- ("example text").should.contain('example');
+ "example text".should.contain('example');
+ "foo".should.not.contain('bar');
({foo: 1, bar: 2}).should.contain.keys('foo');
+
+ (function(){
+ "foo".should.contain('bar');
+ }).should.fail("expected 'foo' to include 'bar'")
});
var subject = $('<div><span>example text</span></div>');

No commit comments for this range

Something went wrong with that request. Please try again.